30 lines
775 B
Rust
30 lines
775 B
Rust
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()
|
|
}
|
|
}
|