idk work (r + h)
This commit is contained in:
52
src/event.rs
52
src/event.rs
@@ -1,5 +1,31 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub mod eventable {
|
||||
use super::*;
|
||||
|
||||
widget_trait! {
|
||||
pub trait Eventable;
|
||||
fn on<E: Event, Ctx: 'static>(
|
||||
self,
|
||||
event: E,
|
||||
f: impl WidgetEventFn<Ctx, E::Data, WL::Widget>,
|
||||
) -> impl WidgetIdFn<WL::Widget> {
|
||||
move |ui| {
|
||||
let id = self.handles(ui);
|
||||
ui.register_event(&id.r, event, move |ctx| {
|
||||
f(EventIdCtx {
|
||||
widget: id.r,
|
||||
state: ctx.state,
|
||||
data: ctx.data,
|
||||
ui: ctx.ui,
|
||||
});
|
||||
});
|
||||
id.h
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: naming in here is a bit weird like eventable
|
||||
#[macro_export]
|
||||
macro_rules! event_ctx {
|
||||
@@ -31,29 +57,3 @@ macro_rules! event_ctx {
|
||||
};
|
||||
}
|
||||
pub use event_ctx;
|
||||
|
||||
pub mod eventable {
|
||||
use super::*;
|
||||
|
||||
widget_trait! {
|
||||
pub trait Eventable;
|
||||
fn on<E: Event, Ctx: 'static>(
|
||||
self,
|
||||
event: E,
|
||||
f: impl WidgetEventFn<Ctx, E::Data, WL::Widget>,
|
||||
) -> impl WidgetIdFn<WL::Widget> {
|
||||
move |ui| {
|
||||
let id = self.handles(ui);
|
||||
ui.register_event(&id.1, event, move |ctx| {
|
||||
f(EventIdCtx {
|
||||
id: id.1,
|
||||
state: ctx.state,
|
||||
data: ctx.data,
|
||||
ui: ctx.ui,
|
||||
});
|
||||
});
|
||||
id.0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user