idk work (r + h)
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
use crate::{Ui, UiModule, WidgetId, WidgetView, util::HashMap};
|
||||
use std::{hash::Hash, rc::Rc};
|
||||
use crate::{Ui, UiModule, Widget, WidgetId, WidgetRef, util::HashMap};
|
||||
use std::{
|
||||
hash::Hash,
|
||||
ops::{Index, IndexMut},
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
pub trait Event: Sized {
|
||||
type Module<Ctx: 'static>: EventModule<Self, Ctx>;
|
||||
@@ -13,12 +17,32 @@ pub struct EventCtx<'a, Ctx, Data> {
|
||||
}
|
||||
|
||||
pub struct EventIdCtx<'a, Ctx, Data, W: ?Sized> {
|
||||
pub id: WidgetView<W>,
|
||||
pub widget: WidgetRef<W>,
|
||||
pub ui: &'a mut Ui,
|
||||
pub state: &'a mut Ctx,
|
||||
pub data: 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]
|
||||
}
|
||||
}
|
||||
|
||||
pub trait EventFn<Ctx, Data>: Fn(EventCtx<Ctx, Data>) + 'static {}
|
||||
impl<F: Fn(EventCtx<Ctx, Data>) + 'static, Ctx, Data> EventFn<Ctx, Data> for F {}
|
||||
|
||||
@@ -127,7 +151,7 @@ impl Ui {
|
||||
pub fn run_event<E: Event, Ctx: 'static, W>(
|
||||
&mut self,
|
||||
ctx: &mut Ctx,
|
||||
id: WidgetView<W>,
|
||||
id: WidgetRef<W>,
|
||||
event: E,
|
||||
data: E::Data,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user