From f4975df57b6763ad087d462ae65fd300d9e3ecf1 Mon Sep 17 00:00:00 2001 From: Shadow Cat Date: Wed, 13 Aug 2025 02:07:35 -0400 Subject: [PATCH] widget fn ret macro --- src/base/trait_fns.rs | 14 +++----------- src/layout/widget.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/base/trait_fns.rs b/src/base/trait_fns.rs index e27fa05..fb873f8 100644 --- a/src/base/trait_fns.rs +++ b/src/base/trait_fns.rs @@ -1,5 +1,5 @@ use super::*; -use crate::{UIRegion, Ui, Vec2, WidgetArrLike, WidgetFn, WidgetLike}; +use crate::{UIRegion, Ui, Vec2, WidgetArrLike, WidgetFn, WidgetFnRet, WidgetLike}; pub trait BaseWidget { fn pad(self, padding: impl Into) -> impl WidgetLike; @@ -23,19 +23,11 @@ impl BaseWidget for W { } pub trait BaseWidgetArr { - fn span( - self, - dir: Dir, - lengths: [impl Into; LEN], - ) -> WidgetFn Span, Span>; + fn span(self, dir: Dir, lengths: [impl Into; LEN]) -> WidgetFnRet!(Span); } impl> BaseWidgetArr for Wa { - fn span( - self, - dir: Dir, - lengths: [impl Into; LEN], - ) -> WidgetFn Span, Span> { + fn span(self, dir: Dir, lengths: [impl Into; LEN]) -> WidgetFnRet!(Span) { let lengths = lengths.map(Into::into); WidgetFn(move |ui| Span { dir, diff --git a/src/layout/widget.rs b/src/layout/widget.rs index 4b8e0fc..9aec149 100644 --- a/src/layout/widget.rs +++ b/src/layout/widget.rs @@ -59,9 +59,17 @@ pub trait WidgetLike { /// A function that returns a widget given a UI. /// Useful for defining trait functions on widgets that create a parent widget so that the children /// don't need to be IDs yet +pub trait WFn = FnOnce(&mut Ui) -> W; pub struct WidgetFn W, W>(pub F); pub struct WidgetIdFn WidgetId, W>(pub F); +macro_rules! WidgetFnRet { + ($W:ident) => { + WidgetFn $W, $W> + }; +} +pub(crate) use WidgetFnRet; + pub trait _WidgetFn { fn call(ui: &mut Ui) -> W; }