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