From 6f374b6719a7b9bc1541a1dfd09c4149912f4b87 Mon Sep 17 00:00:00 2001 From: Taylor Holliday Date: Sun, 10 Dec 2023 09:25:48 -0800 Subject: [PATCH] Pass delta --- src/modifiers.rs | 2 +- src/views/drag_p.rs | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/modifiers.rs b/src/modifiers.rs index fc490f0..32b0ff5 100644 --- a/src/modifiers.rs +++ b/src/modifiers.rs @@ -41,7 +41,7 @@ pub trait Modifiers: View + Sized { self, f: F, ) -> DragP> { - DragP::new(self, DragFuncP{f}) + DragP::new(self, DragFuncP { f }) } /// Calls a function in response to a drag. Version which passes in a binding. diff --git a/src/views/drag_p.rs b/src/views/drag_p.rs index 317b5df..060af01 100644 --- a/src/views/drag_p.rs +++ b/src/views/drag_p.rs @@ -7,6 +7,7 @@ pub trait DragFn { &self, cx: &mut Context, pt: LocalPoint, + delta: LocalOffset, state: GestureState, button: Option, actions: &mut Vec>, @@ -24,6 +25,7 @@ impl, actions: &mut Vec>, @@ -82,17 +84,30 @@ where cx.previous_position[*id] = *position; cx.grab_cursor = self.grab; - self.func.call(cx, *position, GestureState::Began, cx.mouse_button, actions); + self.func.call( + cx, + *position, + LocalOffset::zero(), + GestureState::Began, + cx.mouse_button, + actions, + ); } } Event::TouchMove { id, position, - delta: _, + delta, } => { if cx.touches[*id] == vid { - - self.func.call(cx, *position, GestureState::Changed, cx.mouse_button, actions); + self.func.call( + cx, + *position, + *delta, + GestureState::Changed, + cx.mouse_button, + actions, + ); cx.previous_position[*id] = *position; } } @@ -101,7 +116,14 @@ where cx.touches[*id] = ViewId::default(); cx.grab_cursor = false; - self.func.call(cx, *position, GestureState::Ended, cx.mouse_button, actions); + self.func.call( + cx, + *position, + LocalOffset::zero(), + GestureState::Ended, + cx.mouse_button, + actions, + ); } } _ => (),