RE ADD CONTEXT
This commit is contained in:
1 parent
dc2be7f688
commit
0b8a93c5ce
39 files changed
+925
-713
No files matched your search
+16
-18
@@ -1,36 +1,34 @@
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use crate::{Ui, Widget, WidgetRef};
|
||||
use crate::{HasUi, Ui, Widget, WidgetRef};
|
||||
|
||||
pub struct EventCtx<'a, Ctx, Data> {
|
||||
pub ui: &'a mut Ui,
|
||||
pub state: &'a mut Ctx,
|
||||
pub struct EventCtx<'a, State, Data> {
|
||||
pub state: &'a mut State,
|
||||
pub data: &'a mut Data,
|
||||
}
|
||||
|
||||
pub struct EventIdCtx<'a, Ctx, Data, W: ?Sized> {
|
||||
pub widget: WidgetRef<W>,
|
||||
pub ui: &'a mut Ui,
|
||||
pub state: &'a mut Ctx,
|
||||
pub struct EventIdCtx<'a, State, Data, W: ?Sized> {
|
||||
pub widget: WidgetRef<State, W>,
|
||||
pub state: &'a mut State,
|
||||
pub data: &'a mut Data,
|
||||
}
|
||||
|
||||
impl<'a, Ctx, Data, W2, W: Widget> Index<WidgetRef<W>> for EventIdCtx<'a, Ctx, Data, W2> {
|
||||
type Output = W;
|
||||
impl<State: HasUi, Data, W: ?Sized> Deref for EventIdCtx<'_, State, Data, W> {
|
||||
type Target = Ui<State>;
|
||||
|
||||
fn index(&self, index: WidgetRef<W>) -> &Self::Output {
|
||||
&self.ui[index]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.state.ui_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx, Data, W2, W: Widget> IndexMut<WidgetRef<W>> for EventIdCtx<'a, Ctx, Data, W2> {
|
||||
fn index_mut(&mut self, index: WidgetRef<W>) -> &mut Self::Output {
|
||||
&mut self.ui[index]
|
||||
impl<State: HasUi, Data, W: ?Sized> DerefMut for EventIdCtx<'_, State, Data, W> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.state.ui()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx, Data, W: Widget> EventIdCtx<'a, Ctx, Data, W> {
|
||||
impl<'a, State: HasUi + 'static, Data, W: Widget<State>> EventIdCtx<'a, State, Data, W> {
|
||||
pub fn widget(&mut self) -> &mut W {
|
||||
&mut self.ui[self.widget]
|
||||
&mut self.state.ui()[self.widget]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user