@@ -521,20 +521,10 @@ impl Item for SwipeGestureHandler {
521
521
InputEventFilterResult :: Intercept
522
522
} else if !self . pressed . get ( ) {
523
523
InputEventFilterResult :: ForwardEvent
524
+ } else if self . is_over_threshold ( position) {
525
+ InputEventFilterResult :: Intercept
524
526
} else {
525
- let pressed_pos = self . pressed_position ( ) ;
526
- let dx = position. x - pressed_pos. x as Coord ;
527
- let dy = position. y - pressed_pos. y as Coord ;
528
- let threshold = super :: flickable:: DISTANCE_THRESHOLD . get ( ) ;
529
- if ( self . handle_swipe_down ( ) && dy > threshold)
530
- || ( self . handle_swipe_up ( ) && dy < -threshold)
531
- || ( self . handle_swipe_left ( ) && dx < -threshold)
532
- || ( self . handle_swipe_right ( ) && dx > threshold)
533
- {
534
- InputEventFilterResult :: Intercept
535
- } else {
536
- InputEventFilterResult :: ForwardAndInterceptGrab
537
- }
527
+ InputEventFilterResult :: ForwardAndInterceptGrab
538
528
}
539
529
}
540
530
MouseEvent :: Wheel { .. } => InputEventFilterResult :: ForwardAndIgnore ,
@@ -576,25 +566,20 @@ impl Item for SwipeGestureHandler {
576
566
}
577
567
MouseEvent :: Moved { position } => {
578
568
if !self . pressed . get ( ) {
579
- return InputEventResult :: EventIgnored ;
569
+ return InputEventResult :: EventAccepted ;
580
570
}
581
571
self . current_position . set ( crate :: lengths:: logical_position_to_api ( * position) ) ;
582
- if !self . swiping ( ) {
583
- let pressed_pos = self . pressed_position ( ) ;
584
- let dx = position. x - pressed_pos. x as Coord ;
585
- let dy = position. y - pressed_pos. y as Coord ;
586
- let threshold = super :: flickable:: DISTANCE_THRESHOLD . get ( ) ;
587
- let start_swipe = ( self . handle_swipe_down ( ) && dy > threshold)
588
- || ( self . handle_swipe_up ( ) && dy < -threshold)
589
- || ( self . handle_swipe_left ( ) && dx < -threshold)
590
- || ( self . handle_swipe_right ( ) && dx > threshold) ;
591
-
592
- if start_swipe {
593
- Self :: FIELD_OFFSETS . swiping . apply_pin ( self ) . set ( true ) ;
594
- }
572
+ let mut swiping = self . swiping ( ) ;
573
+ if !swiping && self . is_over_threshold ( position) {
574
+ Self :: FIELD_OFFSETS . swiping . apply_pin ( self ) . set ( true ) ;
575
+ swiping = true ;
595
576
}
596
577
Self :: FIELD_OFFSETS . moved . apply_pin ( self ) . call ( & ( ) ) ;
597
- InputEventResult :: GrabMouse
578
+ if swiping {
579
+ InputEventResult :: GrabMouse
580
+ } else {
581
+ InputEventResult :: EventAccepted
582
+ }
598
583
}
599
584
MouseEvent :: Wheel { .. } => InputEventResult :: EventIgnored ,
600
585
MouseEvent :: DragMove ( ..) | MouseEvent :: Drop ( ..) => InputEventResult :: EventIgnored ,
@@ -672,6 +657,17 @@ impl SwipeGestureHandler {
672
657
Self :: FIELD_OFFSETS . cancelled . apply_pin ( self ) . call ( & ( ) ) ;
673
658
}
674
659
}
660
+
661
+ fn is_over_threshold ( self : Pin < & Self > , position : & LogicalPoint ) -> bool {
662
+ let pressed_pos = self . pressed_position ( ) ;
663
+ let dx = position. x - pressed_pos. x as Coord ;
664
+ let dy = position. y - pressed_pos. y as Coord ;
665
+ let threshold = super :: flickable:: DISTANCE_THRESHOLD . get ( ) ;
666
+ ( self . handle_swipe_down ( ) && dy > threshold && dy > dx. abs ( ) / 2 as Coord )
667
+ || ( self . handle_swipe_up ( ) && dy < -threshold && dy < -dx. abs ( ) / 2 as Coord )
668
+ || ( self . handle_swipe_left ( ) && dx < -threshold && dx < -dy. abs ( ) / 2 as Coord )
669
+ || ( self . handle_swipe_right ( ) && dx > threshold && dx > dy. abs ( ) / 2 as Coord )
670
+ }
675
671
}
676
672
677
673
#[ cfg( feature = "ffi" ) ]
0 commit comments