refactor events
This commit is contained in:
1 parent
a2a32b4322
commit
9d8ca8fa72
4 files changed
+75
-94
No files matched your search
@@ -0,0 +1,36 @@
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
use crate::{Ui, Widget, WidgetRef};
|
||||
|
||||
pub struct EventCtx<'a, Ctx, Data> {
|
||||
pub ui: &'a mut Ui,
|
||||
pub state: &'a mut Ctx,
|
||||
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 data: &'a mut Data,
|
||||
}
|
||||
|
||||
impl<'a, Ctx, Data, W2, W: Widget> Index<WidgetRef<W>> for EventIdCtx<'a, Ctx, Data, W2> {
|
||||
type Output = W;
|
||||
|
||||
fn index(&self, index: WidgetRef<W>) -> &Self::Output {
|
||||
&self.ui[index]
|
||||
}
|
||||
}
|
||||
|
||||
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<'a, Ctx, Data, W: Widget> EventIdCtx<'a, Ctx, Data, W> {
|
||||
pub fn widget(&mut self) -> &mut W {
|
||||
&mut self.ui[self.widget]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user