Skip to content

Commit

Permalink
Pass delta
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Dec 10, 2023
1 parent 53c92e5 commit 6f374b6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait Modifiers: View + Sized {
self,
f: F,
) -> DragP<Self, DragFuncP<F>> {
DragP::new(self, DragFuncP{f})
DragP::new(self, DragFuncP { f })
}

/// Calls a function in response to a drag. Version which passes in a binding.
Expand Down
32 changes: 27 additions & 5 deletions src/views/drag_p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub trait DragFn {
&self,
cx: &mut Context,
pt: LocalPoint,
delta: LocalOffset,
state: GestureState,
button: Option<MouseButton>,
actions: &mut Vec<Box<dyn Any>>,
Expand All @@ -24,6 +25,7 @@ impl<A: 'static, F: Fn(&mut Context, LocalPoint, GestureState, Option<MouseButto
&self,
cx: &mut Context,
pt: LocalPoint,
_delta: LocalOffset,
state: GestureState,
button: Option<MouseButton>,
actions: &mut Vec<Box<dyn Any>>,
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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,
);
}
}
_ => (),
Expand Down

0 comments on commit 6f374b6

Please sign in to comment.