60 lines
1.4 KiB
Rust
60 lines
1.4 KiB
Rust
use crate::{HasEvents, HasState, HasUi, Ui, Widget, WidgetRef};
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
pub struct EventCtx<'a, State, Data> {
|
|
pub state: &'a mut State,
|
|
pub data: &'a mut Data,
|
|
}
|
|
|
|
pub struct EventIdCtx<'a, State, Data, W: ?Sized> {
|
|
pub widget: WidgetRef<W>,
|
|
pub state: &'a mut State,
|
|
pub data: &'a mut Data,
|
|
}
|
|
|
|
impl<State: HasUi, Data, W: ?Sized> Deref for EventIdCtx<'_, State, Data, W> {
|
|
type Target = State;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
self.state
|
|
}
|
|
}
|
|
|
|
impl<State: HasUi, Data, W: ?Sized> DerefMut for EventIdCtx<'_, State, Data, W> {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
self.state
|
|
}
|
|
}
|
|
|
|
impl<'a, State: HasUi, Data, W: Widget> EventIdCtx<'a, State, Data, W> {
|
|
pub fn widget(&mut self) -> &mut W {
|
|
&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()
|
|
}
|
|
}
|