remove state generic from a lot of things
This commit is contained in:
1 parent
7e6369029f
commit
30bc55c78e
45 files changed
+740
-856
No files matched your search
@@ -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