clean up a bit
This commit is contained in:
@@ -264,13 +264,9 @@ impl<E: Event<Ctx, Data = <Senses as Event<Ctx>>::Data> + Into<Senses>, Ctx: 'st
|
||||
});
|
||||
}
|
||||
|
||||
fn run<'a>(
|
||||
&mut self,
|
||||
id: &Id,
|
||||
event: E,
|
||||
) -> Option<impl Fn(&mut Ctx, E::Data) + use<'a, E, Ctx>> {
|
||||
fn run<'a>(&self, id: &Id, event: E) -> Option<impl Fn(&mut Ctx, E::Data) + use<'a, E, Ctx>> {
|
||||
let senses = event.into();
|
||||
if let Some(group) = self.map.get_mut(id) {
|
||||
if let Some(group) = self.map.get(id) {
|
||||
let fs: Vec<_> = group
|
||||
.sensors
|
||||
.iter()
|
||||
|
||||
@@ -65,7 +65,7 @@ impl<W: WidgetLike<Tag>, Tag> Eventable<W::Widget, Tag> for W {
|
||||
fn id_on<E: Event<Ctx>, Ctx>(
|
||||
self,
|
||||
event: E,
|
||||
mut f: impl Fn(&WidgetId<W::Widget>, &mut Ctx, E::Data) + 'static,
|
||||
f: impl Fn(&WidgetId<W::Widget>, &mut Ctx, E::Data) + 'static,
|
||||
) -> impl WidgetIdFn<W::Widget>
|
||||
where
|
||||
W::Widget: Widget,
|
||||
@@ -79,7 +79,7 @@ impl<W: WidgetLike<Tag>, Tag> Eventable<W::Widget, Tag> for W {
|
||||
fn edit_on<E: Event<Ui>>(
|
||||
self,
|
||||
event: E,
|
||||
mut f: impl Fn(&mut W::Widget, E::Data) + 'static,
|
||||
f: impl Fn(&mut W::Widget, E::Data) + 'static,
|
||||
) -> impl WidgetIdFn<W::Widget>
|
||||
where
|
||||
W::Widget: Widget,
|
||||
@@ -100,7 +100,7 @@ impl<E: DefaultEvent, Ctx: 'static> Event<Ctx> for E {
|
||||
pub trait EventModule<E: Event<Ctx>, Ctx>: UiModule + Default {
|
||||
fn register(&mut self, id: Id, event: E, f: impl EventFn<Ctx, E::Data>);
|
||||
fn run<'a>(
|
||||
&mut self,
|
||||
&self,
|
||||
id: &Id,
|
||||
event: E,
|
||||
) -> Option<impl Fn(&mut Ctx, E::Data) + use<'a, Self, E, Ctx>>;
|
||||
@@ -132,12 +132,8 @@ impl<E: HashableEvent<Ctx>, Ctx: 'static> EventModule<E, Ctx> for DefaultEventMo
|
||||
.push(Rc::new(f));
|
||||
}
|
||||
|
||||
fn run<'a>(
|
||||
&mut self,
|
||||
id: &Id,
|
||||
event: E,
|
||||
) -> Option<impl Fn(&mut Ctx, E::Data) + use<'a, E, Ctx>> {
|
||||
if let Some(map) = self.map.get_mut(&event)
|
||||
fn run<'a>(&self, id: &Id, event: E) -> Option<impl Fn(&mut Ctx, E::Data) + use<'a, E, Ctx>> {
|
||||
if let Some(map) = self.map.get(&event)
|
||||
&& let Some(fs) = map.get(id)
|
||||
{
|
||||
let fs = fs.clone();
|
||||
@@ -153,31 +149,18 @@ impl<E: HashableEvent<Ctx>, Ctx: 'static> EventModule<E, Ctx> for DefaultEventMo
|
||||
}
|
||||
|
||||
impl<E: HashableEvent<Ctx>, Ctx: 'static> DefaultEventModule<E, Ctx> {
|
||||
pub fn run_all(&mut self, ctx: &mut Ctx, event: E, data: E::Data)
|
||||
pub fn run_all(&self, ctx: &mut Ctx, event: E, data: E::Data)
|
||||
where
|
||||
E::Data: Clone,
|
||||
{
|
||||
if let Some(map) = self.map.get_mut(&event) {
|
||||
for fs in map.values_mut() {
|
||||
if let Some(map) = self.map.get(&event) {
|
||||
for fs in map.values() {
|
||||
for f in fs {
|
||||
f(ctx, data.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run<W>(&mut self, ctx: &mut Ctx, id: WidgetId<W>, event: E, data: E::Data)
|
||||
where
|
||||
E::Data: Clone,
|
||||
{
|
||||
if let Some(map) = self.map.get_mut(&event)
|
||||
&& let Some(fs) = map.get_mut(&id.id)
|
||||
{
|
||||
for f in fs {
|
||||
f(ctx, data.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Event<Ctx> + 'static, Ctx: 'static> Default for DefaultEventModule<E, Ctx> {
|
||||
|
||||
Reference in New Issue
Block a user