Skip to content

Commit 5ca4bc3

Browse files
committed
Adjust flick detection
1 parent 90dfacb commit 5ca4bc3

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

crates/egui_router/src/router.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ enum SwipeBackGestureState {
2020
Swiping {
2121
/// Distance swiped in pixels
2222
distance: f32,
23-
/// Horizontal velocity in pixels per second
24-
velocity: f32,
2523
},
2624
}
2725

@@ -369,7 +367,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
369367
}) && !ui.ctx().is_being_dragged(gesture_id);
370368

371369
if sense.contains_pointer() && !is_something_blocking_drag {
372-
let (pointer_pos, delta, any_released, dt) = ui.input(|input| {
370+
let (pointer_pos, delta, any_released, velocity) = ui.input(|input| {
373371
(
374372
input.pointer.interact_pos(),
375373
if input.pointer.is_decidedly_dragging() {
@@ -378,7 +376,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
378376
None
379377
},
380378
input.pointer.any_released(),
381-
input.stable_dt,
379+
input.pointer.velocity(),
382380
)
383381
});
384382

@@ -391,7 +389,6 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
391389
// Start the gesture
392390
gesture_state = SwipeBackGestureState::Swiping {
393391
distance: 0.0,
394-
velocity: 0.0,
395392
};
396393

397394
// Start a manual backward transition
@@ -414,12 +411,8 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
414411
// Update the gesture distance (only positive horizontal movement)
415412
let new_distance = (distance + delta.x).max(0.0);
416413

417-
// Calculate velocity (pixels per second)
418-
let new_velocity = if dt > 0.0 { delta.x / dt } else { 0.0 };
419-
420414
gesture_state = SwipeBackGestureState::Swiping {
421415
distance: new_distance,
422-
velocity: new_velocity,
423416
};
424417

425418
if new_distance > 10.0 {
@@ -438,16 +431,16 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
438431
}
439432

440433
if any_released {
441-
if let SwipeBackGestureState::Swiping { distance, velocity } = gesture_state {
434+
if let SwipeBackGestureState::Swiping { distance } = gesture_state {
442435
// Velocity threshold for flick gesture (pixels per second)
443-
const FLICK_VELOCITY_THRESHOLD: f32 = 500.0;
436+
const FLICK_VELOCITY_THRESHOLD: f32 = 100.0;
444437

445438
let screen_width = content_rect.width();
446439
let progress = distance / screen_width;
447440

448441
// Check if we've swiped far enough OR flicked fast enough to trigger back navigation
449442
let should_navigate_back = progress >= self.swipe_back_threshold
450-
|| velocity >= FLICK_VELOCITY_THRESHOLD;
443+
|| velocity.x >= FLICK_VELOCITY_THRESHOLD;
451444

452445
if should_navigate_back {
453446
let popped = self.history.pop();

0 commit comments

Comments
 (0)