finished moving out render_state

This commit is contained in:
iris committed 2026-01-19 18:00:24 -05:00
1 parent 79813db3ba
commit 06dd015092
26 files changed
+496 -220

No files matched your search

+1 -1
View File
@@ -13,6 +13,6 @@ pub struct EventIdCtx<'a, Rsc: HasEvents, Data, W: ?Sized> {
impl<Rsc: HasEvents, Data, W: Widget> EventIdCtx<'_, Rsc, Data, W> {
pub fn widget<'a>(&self, rsc: &'a mut Rsc) -> &'a mut W {
&mut rsc.widgets_mut()[self.widget]
&mut rsc.ui_mut().widgets[self.widget]
}
}
+5 -5
View File
@@ -1,6 +1,6 @@
use crate::{
ActiveData, Event, EventCtx, EventFn, EventIdCtx, EventLike, HasEvents, IdLike, LayerId,
Widget, WidgetEventFn, WidgetId, WeakWidget,
WeakWidget, Widget, WidgetEventFn, WidgetId,
util::{HashMap, HashSet, TypeMap},
};
use std::{any::TypeId, rc::Rc};
@@ -28,7 +28,7 @@ impl<Rsc: HasEvents + 'static> EventManager<Rsc> {
&mut self,
id: WeakWidget<W>,
event: E,
f: impl WidgetEventFn<Rsc, <E::Event as Event>::Data, W>,
f: impl for<'a> WidgetEventFn<Rsc, <E::Event as Event>::Data<'a>, 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 EventFn<Rsc, <E as Event>::Data>>);
type EventData<Rsc, E> = (E, Rc<dyn for<'a> EventFn<Rsc, <E as Event>::Data<'a>>>);
pub struct TypeEventManager<Rsc: HasEvents, E: Event> {
// TODO: reduce visiblity!!
pub active: HashMap<LayerId, HashMap<WidgetId, E::State>>,
@@ -116,7 +116,7 @@ impl<Rsc: HasEvents + 'static, E: Event> TypeEventManager<Rsc, E> {
&mut self,
widget: WeakWidget<W>,
event: impl EventLike<Event = E>,
f: impl WidgetEventFn<Rsc, E::Data, W>,
f: impl for<'a> WidgetEventFn<Rsc, E::Data<'a>, W>,
) {
let event = event.into_event();
self.map.entry(widget.id()).or_default().push((
@@ -137,7 +137,7 @@ impl<Rsc: HasEvents + 'static, E: Event> TypeEventManager<Rsc, E> {
pub fn run_fn<'a>(
&mut self,
id: impl IdLike,
) -> impl FnOnce(EventCtx<'_, Rsc, E::Data>, &mut Rsc) + 'a {
) -> impl for<'b> FnOnce(EventCtx<'_, Rsc, E::Data<'b>>, &mut Rsc) + 'a {
let fs = self.map.get(&id.id()).cloned().unwrap_or_default();
move |ctx, rsc| {
for (e, f) in fs {
+2 -2
View File
@@ -7,10 +7,10 @@ pub use manager::*;
pub use rsc::*;
pub trait Event: Sized + 'static + Clone {
type Data: Clone = ();
type Data<'a>: Clone = ();
type State: Default = ();
#[allow(unused_variables)]
fn should_run(&self, data: &Self::Data) -> Option<Self::Data> {
fn should_run<'a>(&self, data: &Self::Data<'a>) -> Option<Self::Data<'a>> {
Some(data.clone())
}
}
+3 -3
View File
@@ -1,5 +1,5 @@
use crate::{
Event, EventCtx, EventLike, EventManager, IdLike, UiRsc, Widget, WidgetEventFn, WeakWidget,
Event, EventCtx, EventLike, EventManager, IdLike, UiRsc, WeakWidget, Widget, WidgetEventFn,
};
pub trait HasState: 'static {
@@ -14,7 +14,7 @@ pub trait HasEvents: Sized + UiRsc + HasState {
&mut self,
id: WeakWidget<W>,
event: E,
f: impl WidgetEventFn<Self, <E::Event as Event>::Data, W>,
f: impl for<'a> WidgetEventFn<Self, <E::Event as Event>::Data<'a>, W>,
) {
self.events_mut().register(id, event, f);
}
@@ -24,7 +24,7 @@ pub trait RunEvents: HasEvents {
fn run_event<E: EventLike>(
&mut self,
id: impl IdLike,
data: <E::Event as Event>::Data,
data: <E::Event as Event>::Data<'_>,
state: &mut Self::State,
) {
let f = self.events_mut().get_type::<E>().run_fn(id);