remove state generic from a lot of things
This commit is contained in:
29
core/src/event/rsc.rs
Normal file
29
core/src/event/rsc.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use crate::{Event, EventCtx, EventLike, EventManager, HasEvents, HasUi, IdLike};
|
||||
|
||||
pub trait HasRsc: Sized + 'static {
|
||||
type Rsc: HasEvents<State = Self> + HasUi;
|
||||
fn rsc(&self) -> &Self::Rsc;
|
||||
fn rsc_mut(&mut self) -> &mut Self::Rsc;
|
||||
|
||||
fn run_event<E: EventLike>(&mut self, id: impl IdLike, data: &mut <E::Event as Event>::Data<'_>)
|
||||
where
|
||||
Self: 'static,
|
||||
{
|
||||
let f = self.rsc_mut().events().get_type::<E>().run_fn(id);
|
||||
f(EventCtx { state: self, data })
|
||||
}
|
||||
|
||||
fn events(&mut self) -> &mut EventManager<Self> {
|
||||
self.rsc_mut().events()
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: HasRsc> HasUi for R {
|
||||
fn ui_ref(&self) -> &crate::Ui {
|
||||
self.rsc().ui_ref()
|
||||
}
|
||||
|
||||
fn ui(&mut self) -> &mut crate::Ui {
|
||||
self.rsc_mut().ui()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user