RE ADD CONTEXT

This commit is contained in:
2025-12-15 21:50:53 -05:00
parent dc2be7f688
commit 0b8a93c5ce
39 changed files with 925 additions and 713 deletions

View File

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