26 lines
773 B
Rust
26 lines
773 B
Rust
use crate::prelude::*;
|
|
|
|
pub mod eventable {
|
|
use super::*;
|
|
widget_trait! {
|
|
pub trait Eventable<State: HasEvents + StateLike<State> + 'static>;
|
|
fn on<E: EventLike>(
|
|
self,
|
|
event: E,
|
|
f: impl for<'a> WidgetEventFn<State::State, <E::Event as Event>::Data<'a>, WL::Widget>,
|
|
) -> impl WidgetIdFn<State, WL::Widget> {
|
|
move |state| {
|
|
let id = self.add(state);
|
|
state.register_event(id, event.into_event(), move |ctx| {
|
|
f(&mut EventIdCtx {
|
|
widget: id,
|
|
state: ctx.state,
|
|
data: ctx.data,
|
|
});
|
|
});
|
|
id
|
|
}
|
|
}
|
|
}
|
|
}
|