remove typed stuff / just specify rsc if needed

This commit is contained in:
2026-01-03 18:06:05 -05:00
parent 59901b6580
commit f2ac6f195f
14 changed files with 126 additions and 164 deletions

View File

@@ -28,7 +28,7 @@ impl<Rsc: HasEvents + 'static> EventManager<Rsc> {
&mut self,
id: WidgetRef<W>,
event: E,
f: impl for<'a> WidgetEventFn<Rsc, <E::Event as Event>::Data<'a>, W>,
f: impl WidgetEventFn<Rsc, <E::Event as Event>::Data, W>,
) {
self.get_type::<E>().register(id, event, f);
self.widget_to_types
@@ -74,7 +74,7 @@ pub trait EventManagerLike<State> {
fn undraw(&mut self, data: &ActiveData);
}
type EventData<Rsc, E> = (E, Rc<dyn for<'a> EventFn<Rsc, <E as Event>::Data<'a>>>);
type EventData<Rsc, E> = (E, Rc<dyn EventFn<Rsc, <E as Event>::Data>>);
pub struct TypeEventManager<Rsc: HasEvents, E: Event> {
// TODO: reduce visiblity!!
pub active: HashMap<LayerId, HashMap<WidgetId, E::State>>,
@@ -116,18 +116,20 @@ impl<Rsc: HasEvents + 'static, E: Event> TypeEventManager<Rsc, E> {
&mut self,
widget: WidgetRef<W>,
event: impl EventLike<Event = E>,
f: impl for<'a> WidgetEventFn<Rsc, E::Data<'a>, W>,
f: impl WidgetEventFn<Rsc, E::Data, W>,
) {
let event = event.into_event();
self.map.entry(widget.id()).or_default().push((
event,
Rc::new(move |ctx, rsc| {
let mut test = EventIdCtx {
widget,
state: ctx.state,
data: ctx.data,
};
f(&mut test, rsc);
f(
EventIdCtx {
widget,
state: ctx.state,
data: ctx.data,
},
rsc,
);
}),
));
}
@@ -135,15 +137,15 @@ impl<Rsc: HasEvents + 'static, E: Event> TypeEventManager<Rsc, E> {
pub fn run_fn<'a>(
&mut self,
id: impl IdLike,
) -> impl for<'b> FnOnce(EventCtx<'_, Rsc, E::Data<'b>>, &mut Rsc) + 'a {
) -> impl FnOnce(EventCtx<'_, Rsc, E::Data>, &mut Rsc) + 'a {
let fs = self.map.get(&id.id()).cloned().unwrap_or_default();
move |ctx, rsc| {
for (e, f) in fs {
if e.should_run(ctx.data) {
if let Some(data) = e.should_run(&ctx.data) {
f(
&mut EventCtx {
EventCtx {
state: ctx.state,
data: ctx.data,
data,
},
rsc,
)