remove context from ui (again) and create weird trait for it
This commit is contained in:
1 parent
26c248dcba
commit
719bee4b31
12 files changed
+107
-92
No files matched your search
+1
-1
@@ -15,7 +15,7 @@ impl Widget for Image {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn image<Ctx>(image: impl LoadableImage) -> impl WidgetFn<Image, Ctx> {
|
||||
pub fn image(image: impl LoadableImage) -> impl WidgetFn<Image> {
|
||||
let image = image.get_image().expect("Failed to load image");
|
||||
move |ui| Image {
|
||||
handle: ui.add_texture(image),
|
||||
|
||||
+2
-2
@@ -116,10 +116,10 @@ impl TextBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx> FnOnce<(&mut Ui<Ctx>,)> for TextBuilder {
|
||||
impl FnOnce<(&mut Ui,)> for TextBuilder {
|
||||
type Output = Text;
|
||||
|
||||
extern "rust-call" fn call_once(self, args: (&mut Ui<Ctx>,)) -> Self::Output {
|
||||
extern "rust-call" fn call_once(self, args: (&mut Ui,)) -> Self::Output {
|
||||
let mut buf =
|
||||
TextBuffer::new_empty(Metrics::new(self.attrs.font_size, self.attrs.line_height));
|
||||
buf.set_text(
|
||||
|
||||
@@ -255,10 +255,10 @@ impl TextInputResult {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx> FnOnce<(&mut Ui<Ctx>,)> for TextEditBuilder {
|
||||
impl FnOnce<(&mut Ui,)> for TextEditBuilder {
|
||||
type Output = TextEdit;
|
||||
|
||||
extern "rust-call" fn call_once(self, args: (&mut Ui<Ctx>,)) -> Self::Output {
|
||||
extern "rust-call" fn call_once(self, args: (&mut Ui,)) -> Self::Output {
|
||||
let mut text = TextEdit {
|
||||
buf: TextBuffer::new_empty(Metrics::new(self.attrs.font_size, self.attrs.line_height)),
|
||||
attrs: self.attrs,
|
||||
|
||||
+18
-18
@@ -1,34 +1,34 @@
|
||||
use super::*;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait CoreWidget<W, Ctx, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Padded, Ctx>;
|
||||
fn align(self, align: Align) -> impl WidgetFn<Aligned, Ctx>;
|
||||
fn center(self) -> impl WidgetFn<Aligned, Ctx>;
|
||||
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<W, Ctx>;
|
||||
fn size(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized, Ctx>;
|
||||
pub trait CoreWidget<W, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Padded>;
|
||||
fn align(self, align: Align) -> impl WidgetFn<Aligned>;
|
||||
fn center(self) -> impl WidgetFn<Aligned>;
|
||||
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<W>;
|
||||
fn size(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized>;
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Ctx, Tag>, Ctx, Tag> CoreWidget<W::Widget, Ctx, Tag> for W {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Padded, Ctx> {
|
||||
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Padded> {
|
||||
|ui| Padded {
|
||||
padding: padding.into(),
|
||||
inner: self.add(ui).any(),
|
||||
}
|
||||
}
|
||||
|
||||
fn align(self, align: Align) -> impl WidgetFn<Aligned, Ctx> {
|
||||
fn align(self, align: Align) -> impl WidgetFn<Aligned> {
|
||||
move |ui| Aligned {
|
||||
inner: self.add(ui).any(),
|
||||
align,
|
||||
}
|
||||
}
|
||||
|
||||
fn center(self) -> impl WidgetFn<Aligned, Ctx> {
|
||||
fn center(self) -> impl WidgetFn<Aligned> {
|
||||
self.align(Align::Center)
|
||||
}
|
||||
|
||||
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<W::Widget, Ctx> {
|
||||
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<W::Widget> {
|
||||
|ui| {
|
||||
let id = self.add(ui);
|
||||
ui.set_label(&id, label.into());
|
||||
@@ -36,7 +36,7 @@ impl<W: WidgetLike<Ctx, Tag>, Ctx, Tag> CoreWidget<W::Widget, Ctx, Tag> for W {
|
||||
}
|
||||
}
|
||||
|
||||
fn size(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized, Ctx> {
|
||||
fn size(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized> {
|
||||
move |ui| Sized {
|
||||
inner: self.add(ui).any(),
|
||||
size: size.into(),
|
||||
@@ -44,20 +44,20 @@ impl<W: WidgetLike<Ctx, Tag>, Ctx, Tag> CoreWidget<W::Widget, Ctx, Tag> for W {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CoreWidgetArr<const LEN: usize, Ctx, Tag> {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> impl WidgetFn<Span, Ctx>;
|
||||
fn stack(self) -> impl WidgetFn<Stack, Ctx>;
|
||||
pub trait CoreWidgetArr<const LEN: usize, Tag> {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> impl WidgetFn<Span>;
|
||||
fn stack(self) -> impl WidgetFn<Stack>;
|
||||
}
|
||||
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Ctx, Tag>, Ctx, Tag> CoreWidgetArr<LEN, Ctx, Tag> for Wa {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> impl WidgetFn<Span, Ctx> {
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Tag> for Wa {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> impl WidgetFn<Span> {
|
||||
let lengths = lengths.into_lens();
|
||||
move |ui| Span {
|
||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||
dir,
|
||||
}
|
||||
}
|
||||
fn stack(self) -> impl WidgetFn<Stack, Ctx> {
|
||||
fn stack(self) -> impl WidgetFn<Stack> {
|
||||
move |ui| Stack {
|
||||
children: self.ui(ui).arr.to_vec(),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user