better global state structure?
This commit is contained in:
1 parent
30bc55c78e
commit
bae17235c6
23 files changed
+335
-230
No files matched your search
+32
-7
@@ -1,7 +1,6 @@
|
||||
use crate::{HasEvents, HasState, HasUi, Ui, Widget, WidgetRef};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use crate::{HasUi, Ui, Widget, WidgetRef};
|
||||
|
||||
pub struct EventCtx<'a, State, Data> {
|
||||
pub state: &'a mut State,
|
||||
pub data: &'a mut Data,
|
||||
@@ -14,21 +13,47 @@ pub struct EventIdCtx<'a, State, Data, W: ?Sized> {
|
||||
}
|
||||
|
||||
impl<State: HasUi, Data, W: ?Sized> Deref for EventIdCtx<'_, State, Data, W> {
|
||||
type Target = Ui;
|
||||
type Target = State;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.state.ui_ref()
|
||||
self.state
|
||||
}
|
||||
}
|
||||
|
||||
impl<State: HasUi, Data, W: ?Sized> DerefMut for EventIdCtx<'_, State, Data, W> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.state.ui()
|
||||
self.state
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, State: HasUi + 'static, Data, W: Widget> EventIdCtx<'a, State, Data, W> {
|
||||
impl<'a, State: HasUi, Data, W: Widget> EventIdCtx<'a, State, Data, W> {
|
||||
pub fn widget(&mut self) -> &mut W {
|
||||
&mut self.state.ui()[self.widget]
|
||||
&mut self.state.get_mut()[self.widget]
|
||||
}
|
||||
}
|
||||
|
||||
impl<State: HasUi, Data, W: Widget> HasUi for EventIdCtx<'_, State, Data, W> {
|
||||
fn get(&self) -> &Ui {
|
||||
self.state.ui()
|
||||
}
|
||||
|
||||
fn get_mut(&mut self) -> &mut Ui {
|
||||
self.state.ui_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<State: HasUi, Data, W: Widget> HasState for EventIdCtx<'_, State, Data, W> {
|
||||
type State = State;
|
||||
}
|
||||
|
||||
impl<State: HasEvents<State = State>, Data, W: Widget> HasEvents
|
||||
for EventIdCtx<'_, State, Data, W>
|
||||
{
|
||||
fn get(&self) -> &super::EventManager<Self::State> {
|
||||
self.state.events()
|
||||
}
|
||||
|
||||
fn get_mut(&mut self) -> &mut super::EventManager<Self::State> {
|
||||
self.state.events_mut()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user