abuse macros..

This commit is contained in:
iris committed 2025-12-20 00:26:08 -05:00
1 parent bae17235c6
commit fabc7d0b90
12 files changed
+125 -45

No files matched your search

+59 -2
View File
@@ -1,4 +1,4 @@
use crate::{HasEvents, HasState, HasUi, Ui, Widget, WidgetRef};
use crate::{HasEvents, HasState, HasUi, StateLike, Ui, Widget, WidgetRef};
use std::ops::{Deref, DerefMut};
pub struct EventCtx<'a, State, Data> {
@@ -26,7 +26,7 @@ impl<State: HasUi, Data, W: ?Sized> DerefMut for EventIdCtx<'_, State, Data, W>
}
}
impl<'a, State: HasUi, Data, W: Widget> EventIdCtx<'a, State, Data, W> {
impl<State: HasUi, Data, W: Widget> EventIdCtx<'_, State, Data, W> {
pub fn widget(&mut self) -> &mut W {
&mut self.state.get_mut()[self.widget]
}
@@ -57,3 +57,60 @@ impl<State: HasEvents<State = State>, Data, W: Widget> HasEvents
self.state.events_mut()
}
}
impl<State, Data, W: Widget> StateLike<State> for EventIdCtx<'_, State, Data, W> {
fn as_state(&mut self) -> &mut State {
self.state
}
}
// fn test() {
// use crate::*;
// struct ClientRsc;
// impl<State, Data> HasUi for EventCtx<'_, State, Data> {
// fn get(&self) -> &Ui {
// todo!()
// }
//
// fn get_mut(&mut self) -> &mut Ui {
// todo!()
// }
// }
// fn on(_: impl for<'a> EventFn<ClientRsc, &'a mut i32>) {}
//
// pub trait WidgetLike<State: HasUi, Tag>: Sized {
// type Widget: Widget + ?Sized + std::marker::Unsize<dyn Widget>;
//
// fn add(self, state: &mut State) -> WidgetHandle<Self::Widget>;
//
// fn with_id<W2>(
// self,
// f: impl FnOnce(&mut State, WidgetHandle<Self::Widget>) -> WidgetHandle<W2>,
// ) -> impl WidgetIdFn<State, W2> {
// move |state| {
// let id = self.add(state);
// f(state, id)
// }
// }
//
// fn set_root(self, state: &mut State) {
// state.get_mut().root = Some(self.add(state));
// }
//
// fn handles(self, state: &mut State) -> WidgetHandles<Self::Widget> {
// self.add(state).handles()
// }
// }
//
// pub struct WidgetTag;
// impl<State: HasUi, W: Widget> WidgetLike<State, WidgetTag> for W {
// type Widget = W;
// fn add(self, state: &mut State) -> WidgetHandle<W> {
// state.get_mut().add_widget(self)
// }
// }
//
// on(move |ctx| {
// ().add(ctx);
// });
// }
+4 -3
View File
@@ -116,11 +116,12 @@ impl<State: 'static, E: Event> TypeEventManager<State, E> {
self.map.entry(widget.id()).or_default().push((
event,
Rc::new(move |ctx| {
f(&mut EventIdCtx {
let mut test = EventIdCtx {
widget,
state: ctx.state,
data: ctx.data,
});
};
f(&mut test);
}),
));
}
@@ -128,7 +129,7 @@ impl<State: 'static, E: Event> TypeEventManager<State, E> {
pub fn run_fn<'a>(
&mut self,
id: impl IdLike,
) -> impl for<'b> FnOnce(EventCtx<State, E::Data<'b>>) + 'a {
) -> impl for<'b> FnOnce(EventCtx<'_, State, E::Data<'b>>) + 'a {
let fs = self.map.get(&id.id()).cloned().unwrap_or_default();
move |ctx| {
for (e, f) in fs {