diff --git a/src/event.rs b/src/event.rs index 9134c19..9e74977 100644 --- a/src/event.rs +++ b/src/event.rs @@ -35,15 +35,8 @@ pub use event_ctx; pub mod eventable { use super::*; - pub trait Eventable { - fn on( - self, - event: E, - f: impl WidgetEventFn, - ) -> impl WidgetIdFn + Eventable; - } - - impl, Tag> Eventable for WL { + widget_trait! { + pub trait Eventable; fn on( self, event: E, diff --git a/src/widget/trait_fns.rs b/src/widget/trait_fns.rs index f3cb5c2..684d8f1 100644 --- a/src/widget/trait_fns.rs +++ b/src/widget/trait_fns.rs @@ -4,26 +4,9 @@ use crate::prelude::*; // these methods should "not require any context" (require unit) because they're in core event_ctx!(()); -pub trait CoreWidget { - fn pad(self, padding: impl Into) -> impl WidgetFn; - fn align(self, align: impl Into) -> impl WidgetFn; - fn center(self) -> impl WidgetFn; - fn label(self, label: impl Into) -> impl WidgetIdFn; - fn sized(self, size: impl Into) -> impl WidgetFn; - fn width(self, len: impl Into) -> impl WidgetFn; - fn height(self, len: impl Into) -> impl WidgetFn; - fn max_width(self, width: impl Into) -> impl WidgetFn; - fn max_height(self, height: impl Into) -> impl WidgetFn; - fn offset(self, amt: impl Into) -> impl WidgetFn; - fn scroll(self) -> impl WidgetIdFn; - fn masked(self) -> impl WidgetFn; - fn background(self, w: impl WidgetLike) -> impl WidgetFn; - fn foreground(self, w: impl WidgetLike) -> impl WidgetFn; - fn layer_offset(self, offset: usize) -> impl WidgetFn; - fn to_any(self) -> impl WidgetRet; -} +widget_trait! { + pub trait CoreWidget; -impl, Tag> CoreWidget for W { fn pad(self, padding: impl Into) -> impl WidgetFn { |ui| Pad { padding: padding.into(), @@ -42,7 +25,7 @@ impl, Tag> CoreWidget for W { self.align(Align::CENTER) } - fn label(self, label: impl Into) -> impl WidgetIdFn { + fn label(self, label: impl Into) -> impl WidgetIdFn { |ui| { let id = self.add(ui); ui.set_label(&id, label.into());