diff --git a/core/src/layout/event.rs b/core/src/layout/event.rs index 4a9939b..a7abdb0 100644 --- a/core/src/layout/event.rs +++ b/core/src/layout/event.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, hash::Hash, rc::Rc}; +use std::{hash::Hash, rc::Rc}; use crate::{ layout::{Ui, UiModule, WidgetId, WidgetRef}, @@ -24,11 +24,11 @@ pub struct EventIdCtx<'a, Ctx, Data, W: ?Sized> { pub data: Data, } -pub trait EventFn: FnMut(EventCtx) + 'static {} -impl) + 'static, Ctx, Data> EventFn for F {} +pub trait EventFn: Fn(EventCtx) + 'static {} +impl) + 'static, Ctx, Data> EventFn for F {} -pub trait WidgetEventFn: FnMut(EventIdCtx) + 'static {} -impl) + 'static, Ctx, Data, W: ?Sized> WidgetEventFn +pub trait WidgetEventFn: Fn(EventIdCtx) + 'static {} +impl) + 'static, Ctx, Data, W: ?Sized> WidgetEventFn for F { } @@ -50,13 +50,13 @@ impl Ui { &mut self, id: WidgetRef, event: E, - mut f: impl WidgetEventFn, + f: impl WidgetEventFn, ) { self.data .modules .get_mut::>() .register(id.id(), event, move |ctx| { - (&mut f)(EventIdCtx { + f(EventIdCtx { widget: id, ui: ctx.ui, state: ctx.state, @@ -84,7 +84,7 @@ pub trait EventModule: UiModule + Default { ) -> Option) + use<'a, Self, Ctx, E>>; } -type EventFnMap = HashMap>>>>; +type EventFnMap = HashMap>>>; pub struct DefaultEventModule { map: HashMap::Data>>, } @@ -107,7 +107,7 @@ impl EventModule for DefaultEventModule< .or_default() .entry(id) .or_default() - .push(Rc::new(RefCell::new(f))); + .push(Rc::new(f)); } fn run<'a>( @@ -121,7 +121,7 @@ impl EventModule for DefaultEventModule< let fs = fs.clone(); Some(move |ctx: EventCtx::Data>| { for f in fs { - f.borrow_mut()(EventCtx { + f(EventCtx { ui: ctx.ui, state: ctx.state, data: ctx.data.clone(), @@ -143,7 +143,7 @@ impl DefaultEventModule { for fs in map.values() { let fs = fs.clone(); for f in fs { - f.borrow_mut()(EventCtx { + f(EventCtx { ui: ctx.ui, state: ctx.state, data: ctx.data.clone(), diff --git a/core/src/layout/ui.rs b/core/src/layout/ui.rs index 67d89bc..09ca882 100644 --- a/core/src/layout/ui.rs +++ b/core/src/layout/ui.rs @@ -2,7 +2,7 @@ use image::DynamicImage; use crate::{ layout::{ - IdLike, PainterData, PixelRegion, TextureHandle, Vec2, Widget, WidgetHandle, WidgetId, + IdLike, PainterData, PixelRegion, TextureHandle, Vec2, WidgetHandle, WidgetId, WidgetInstance, WidgetLike, WidgetUpdate, }, util::HashSet, diff --git a/src/default/mod.rs b/src/default/mod.rs index 31eae5d..db00ca2 100644 --- a/src/default/mod.rs +++ b/src/default/mod.rs @@ -91,7 +91,7 @@ impl AppState for DefaultState { let input_changed = ui_state.input.event(&event); let cursor_state = ui_state.cursor_state().clone(); - let old = ui_state.focus.clone(); + let old = ui_state.focus; if cursor_state.buttons.left.is_start() { ui_state.focus = None; } diff --git a/src/widget/sense.rs b/src/widget/sense.rs index 27b3953..f687f91 100644 --- a/src/widget/sense.rs +++ b/src/widget/sense.rs @@ -3,7 +3,6 @@ use crate::{ layout::{UiModule, UiRegion, Vec2}, util::HashMap, }; -use std::cell::RefCell; use std::{ ops::{BitOr, Deref, DerefMut}, rc::Rc, @@ -98,7 +97,7 @@ pub enum ActivationState { /// but I'm not sure how or if worth it pub struct Sensor { pub senses: CursorSenses, - pub f: Rc>>, + pub f: Rc>, } pub type SensorMap = HashMap>; @@ -208,7 +207,7 @@ impl CursorModule { scroll_delta: cursor.scroll_delta, sense, }; - (sensor.f.borrow_mut())(EventCtx { + (sensor.f)(EventCtx { ui, state: ctx, data, @@ -309,7 +308,7 @@ impl::Data> + Into, Ctx: ' // TODO: does not add to active if currently active self.map.entry(id).or_default().sensors.push(Sensor { senses: senses.into(), - f: Rc::new(RefCell::new(f)), + f: Rc::new(f), }); } @@ -333,7 +332,7 @@ impl::Data> + Into, Ctx: ' .collect(); Some(move |ctx: EventCtx| { for f in fs { - f.borrow_mut()(EventCtx { + f(EventCtx { state: ctx.state, ui: ctx.ui, data: ctx.data.clone(),