rename widget fn macros
This commit is contained in:
@@ -15,7 +15,7 @@ impl Widget for Image {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn image(image: impl LoadableImage) -> WidgetFnRet!(Image) {
|
||||
pub fn image(image: impl LoadableImage) -> WidgetFn!(Image) {
|
||||
let image = image.get_image().expect("Failed to load image");
|
||||
move |ui| Image {
|
||||
handle: ui.add_texture(image),
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait Sensable<W, Tag> {
|
||||
fn on(self, sense: Senses, f: impl SenseFn) -> WidgetIdFnRet!(W);
|
||||
fn on(self, sense: Senses, f: impl SenseFn) -> WidgetIdFn!(W);
|
||||
fn id_on(
|
||||
self,
|
||||
senses: Senses,
|
||||
f: impl FnMut(&WidgetId<W>, &mut Ui) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W)
|
||||
) -> WidgetIdFn!(W)
|
||||
where
|
||||
W: Widget;
|
||||
fn edit_on(self, senses: Senses, f: impl FnMut(&mut W) + 'static + Clone) -> WidgetIdFnRet!(W)
|
||||
fn edit_on(self, senses: Senses, f: impl FnMut(&mut W) + 'static + Clone) -> WidgetIdFn!(W)
|
||||
where
|
||||
W: Widget;
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
|
||||
fn on(self, senses: Senses, f: impl SenseFn) -> WidgetIdFnRet!(W::Widget) {
|
||||
fn on(self, senses: Senses, f: impl SenseFn) -> WidgetIdFn!(W::Widget) {
|
||||
move |ui| {
|
||||
let id = self.add(ui);
|
||||
ui.add_sensor(
|
||||
@@ -32,7 +32,7 @@ impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
|
||||
self,
|
||||
senses: Senses,
|
||||
mut f: impl FnMut(&WidgetId<W::Widget>, &mut Ui) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W::Widget)
|
||||
) -> WidgetIdFn!(W::Widget)
|
||||
where
|
||||
W::Widget: Widget,
|
||||
{
|
||||
@@ -45,7 +45,7 @@ impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
|
||||
self,
|
||||
senses: Senses,
|
||||
mut f: impl FnMut(&mut W::Widget) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W::Widget)
|
||||
) -> WidgetIdFn!(W::Widget)
|
||||
where
|
||||
W::Widget: Widget,
|
||||
{
|
||||
|
||||
@@ -2,41 +2,41 @@ use super::*;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait CoreWidget<W, Tag> {
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned);
|
||||
fn align(self, align: Align) -> WidgetFnRet!(Aligned);
|
||||
fn center(self) -> WidgetFnRet!(Aligned);
|
||||
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned);
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W);
|
||||
fn size(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized);
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFn!(Regioned);
|
||||
fn align(self, align: Align) -> WidgetFn!(Aligned);
|
||||
fn center(self) -> WidgetFn!(Aligned);
|
||||
fn region(self, region: UiRegion) -> WidgetFn!(Regioned);
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFn!(W);
|
||||
fn size(self, size: impl Into<Vec2>) -> WidgetFn!(Sized);
|
||||
}
|
||||
|
||||
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned) {
|
||||
fn pad(self, padding: impl Into<Padding>) -> WidgetFn!(Regioned) {
|
||||
|ui| Regioned {
|
||||
region: padding.into().region(),
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
|
||||
fn align(self, align: Align) -> WidgetFnRet!(Aligned) {
|
||||
fn align(self, align: Align) -> WidgetFn!(Aligned) {
|
||||
move |ui| Aligned {
|
||||
inner: self.add(ui).erase_type(),
|
||||
align,
|
||||
}
|
||||
}
|
||||
|
||||
fn center(self) -> WidgetFnRet!(Aligned) {
|
||||
fn center(self) -> WidgetFn!(Aligned) {
|
||||
self.align(Align::Center)
|
||||
}
|
||||
|
||||
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned) {
|
||||
fn region(self, region: UiRegion) -> WidgetFn!(Regioned) {
|
||||
move |ui| Regioned {
|
||||
region,
|
||||
inner: self.add(ui).erase_type(),
|
||||
}
|
||||
}
|
||||
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W::Widget) {
|
||||
fn label(self, label: impl Into<String>) -> WidgetIdFn!(W::Widget) {
|
||||
|ui| {
|
||||
let id = self.add(ui);
|
||||
ui.set_label(&id, label.into());
|
||||
@@ -44,7 +44,7 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
}
|
||||
}
|
||||
|
||||
fn size(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized) {
|
||||
fn size(self, size: impl Into<Vec2>) -> WidgetFn!(Sized) {
|
||||
move |ui| Sized {
|
||||
inner: self.add(ui).erase_type(),
|
||||
size: size.into(),
|
||||
@@ -53,19 +53,19 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
|
||||
}
|
||||
|
||||
pub trait CoreWidgetArr<const LEN: usize, Tag> {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFnRet!(Span);
|
||||
fn stack(self) -> WidgetFnRet!(Stack);
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFn!(Span);
|
||||
fn stack(self) -> WidgetFn!(Stack);
|
||||
}
|
||||
|
||||
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Tag> for Wa {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFnRet!(Span) {
|
||||
fn span(self, dir: Dir, lengths: impl IntoSpanLens<LEN>) -> WidgetFn!(Span) {
|
||||
let lengths = lengths.into_lens();
|
||||
move |ui| Span {
|
||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||
dir,
|
||||
}
|
||||
}
|
||||
fn stack(self) -> WidgetFnRet!(Stack) {
|
||||
fn stack(self) -> WidgetFn!(Stack) {
|
||||
move |ui| Stack {
|
||||
children: self.ui(ui).arr.to_vec(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user