use crate::prelude::*; use iris_macro::widget_trait; // TODO: naming in here is a bit weird like eventable #[macro_export] macro_rules! event_ctx { ($ty: ty) => { mod local_event_trait { use super::*; use std::marker::Sized; #[allow(unused_imports)] use $crate::prelude::*; #[allow(unused)] pub trait EventableCtx { fn on( self, event: E, f: impl WidgetEventFn, ) -> impl WidgetIdFn + EventableCtx; } impl, Tag> EventableCtx for WL { fn on( self, event: E, f: impl WidgetEventFn<$ty, E::Data, WL::Widget>, ) -> impl WidgetIdFn + EventableCtx { eventable::Eventable::on(self, event, f) } } #[allow(unused)] pub trait EventableCtxUi where WidgetRef: EventableCtx, { fn on( &mut self, widget: &WidgetRef, event: E, f: impl WidgetEventFn, ); } impl EventableCtxUi for Ui where WidgetRef: EventableCtx, { fn on( &mut self, widget: &WidgetRef, event: E, f: impl WidgetEventFn<$ty, E::Data, W>, ) { self.register_widget_event(&widget, event, f); } } } use local_event_trait::*; }; } pub use event_ctx; pub mod eventable { use super::*; widget_trait!( pub Eventable; fn on( self, event: E, f: impl WidgetEventFn, ) -> impl WidgetIdFn { move |ui| { let id = self.add(ui); ui.register_widget_event(&id, event, f); id } } ); }