remove modules and have single event manager (atomics feature parity + preparation for local state)

This commit is contained in:
2025-12-12 01:46:24 -05:00
parent a708813ce7
commit 37b1987aa8
17 changed files with 390 additions and 432 deletions

View File

@@ -5,14 +5,14 @@ pub mod eventable {
widget_trait! {
pub trait Eventable;
fn on<E: Event, Ctx: 'static>(
fn on<E: EventLike, Ctx: 'static>(
self,
event: E,
f: impl WidgetEventFn<Ctx, E::Data, WL::Widget>,
f: impl for<'a> WidgetEventFn<Ctx, <E::Event as Event>::Data<'a>, WL::Widget>,
) -> impl WidgetIdFn<WL::Widget> {
move |ui| {
let id = self.handles(ui);
ui.register_event(&id.r, event, move |ctx| {
ui.register_event(id.r, event.into_event(), move |ctx| {
f(EventIdCtx {
widget: id.r,
state: ctx.state,
@@ -35,21 +35,25 @@ macro_rules! event_ctx {
#[allow(unused_imports)]
use $crate::prelude::*;
pub trait EventableCtx<WL: WidgetLike<Tag>, Tag, Ctx: 'static> {
fn on<E: Event>(
widget_trait! {
pub trait EventableCtx;
fn on<E: EventLike>(
self,
event: E,
f: impl WidgetEventFn<Ctx, E::Data, WL::Widget>,
) -> impl WidgetIdFn<WL::Widget>;
}
impl<WL: WidgetLike<Tag>, Tag> EventableCtx<WL, Tag, $ty> for WL {
fn on<E: Event>(
self,
event: E,
f: impl WidgetEventFn<$ty, E::Data, WL::Widget>,
f: impl for<'a> WidgetEventFn<$ty, <E::Event as Event>::Data<'a>, WL::Widget>,
) -> impl WidgetIdFn<WL::Widget> {
eventable::Eventable::on(self, event, f)
move |ui| {
let id = self.handles(ui);
ui.register_event(id.r, event.into_event(), move |ctx| {
f(EventIdCtx {
widget: id.r,
state: ctx.state,
data: ctx.data,
ui: ctx.ui,
});
});
id.h
}
}
}
}