@@ -12,7 +12,10 @@ use num_enum::FromPrimitive;
1212use ui_events:: {
1313 ScrollDelta ,
1414 keyboard:: { KeyboardEvent , Modifiers } ,
15- pointer:: { ContactGeometry , PointerEvent , PointerId , PointerState , PointerUpdate } ,
15+ pointer:: {
16+ ContactGeometry , PointerButtonEvent , PointerEvent , PointerId , PointerScrollEvent ,
17+ PointerState , PointerUpdate ,
18+ } ,
1619} ;
1720
1821use crate :: ViewConfiguration ;
@@ -439,6 +442,8 @@ impl<'local> MotionEvent<'local> {
439442 x : self . axis ( env, Axis :: X , action_index) as f64 ,
440443 y : self . axis ( env, Axis :: Y , action_index) as f64 ,
441444 } ,
445+ // `TapCounter` will attach the scale.
446+ scale_factor : 1.0 ,
442447 buttons,
443448 // `TapCounter` will attach an appropriate count.
444449 count : 0 ,
@@ -469,16 +474,18 @@ impl<'local> MotionEvent<'local> {
469474 } ;
470475
471476 Some ( match action {
472- MotionAction :: Down | MotionAction :: PointerDown => PointerEvent :: Down {
473- pointer,
474- state,
475- button,
476- } ,
477- MotionAction :: Up | MotionAction :: PointerUp => PointerEvent :: Up {
477+ MotionAction :: Down | MotionAction :: PointerDown => {
478+ PointerEvent :: Down ( PointerButtonEvent {
479+ pointer,
480+ state,
481+ button,
482+ } )
483+ }
484+ MotionAction :: Up | MotionAction :: PointerUp => PointerEvent :: Up ( PointerButtonEvent {
478485 pointer,
479486 state,
480487 button,
481- } ,
488+ } ) ,
482489 MotionAction :: Move | MotionAction :: HoverMove => {
483490 let hsz = self . history_size ( env) ;
484491 let mut coalesced: Vec < PointerState > = vec ! [ state. clone( ) ; hsz as usize ] ;
@@ -531,7 +538,7 @@ impl<'local> MotionEvent<'local> {
531538 MotionAction :: Cancel => PointerEvent :: Cancel ( pointer) ,
532539 MotionAction :: HoverEnter => PointerEvent :: Enter ( pointer) ,
533540 MotionAction :: HoverExit => PointerEvent :: Leave ( pointer) ,
534- MotionAction :: Scroll => PointerEvent :: Scroll {
541+ MotionAction :: Scroll => PointerEvent :: Scroll ( PointerScrollEvent {
535542 pointer,
536543 delta : ScrollDelta :: PixelDelta ( PhysicalPosition :: < f64 > {
537544 x : ( self . axis ( env, Axis :: Hscroll , action_index)
@@ -540,7 +547,7 @@ impl<'local> MotionEvent<'local> {
540547 * vc. scaled_vertical_scroll_factor ) as f64 ,
541548 } ) ,
542549 state,
543- } ,
550+ } ) ,
544551 _ => {
545552 // Other current `MotionAction` values relate to gamepad/joystick buttons;
546553 // ui-events doesn't currently have types for these, so consider them unhandled.
@@ -610,25 +617,31 @@ struct TapState {
610617pub struct TapCounter {
611618 /// The `ViewConfiguration` which configures tap counting.
612619 pub vc : ViewConfiguration ,
620+ /// The scale factor.
621+ pub scale_factor : f64 ,
613622 /// Recent taps which can be used for tap counting.
614623 taps : Vec < TapState > ,
615624}
616625
617626impl TapCounter {
618627 /// Make a new `TapCounter` with `ViewConfiguration` from your view.
619- pub fn new ( vc : ViewConfiguration ) -> Self {
620- Self { vc, taps : vec ! [ ] }
628+ pub fn new ( vc : ViewConfiguration , scale_factor : f64 ) -> Self {
629+ Self {
630+ vc,
631+ scale_factor,
632+ taps : vec ! [ ] ,
633+ }
621634 }
622635
623636 /// Enhance a `PointerEvent` with `count`.
624637 ///
625638 pub fn attach_count ( & mut self , e : PointerEvent ) -> PointerEvent {
626639 match e {
627- PointerEvent :: Down {
640+ PointerEvent :: Down ( PointerButtonEvent {
628641 button,
629642 pointer,
630643 state,
631- } => {
644+ } ) => {
632645 let e = if let Some ( i) =
633646 self . taps . iter ( ) . position ( |TapState { x, y, up_time, .. } | {
634647 let dx = ( x - state. position . x ) . abs ( ) ;
@@ -645,11 +658,15 @@ impl TapCounter {
645658 self . taps [ i] . x = state. position . x ;
646659 self . taps [ i] . y = state. position . y ;
647660
648- PointerEvent :: Down {
661+ PointerEvent :: Down ( PointerButtonEvent {
649662 button,
650663 pointer,
651- state : PointerState { count, ..state } ,
652- }
664+ state : PointerState {
665+ count,
666+ scale_factor : self . scale_factor ,
667+ ..state
668+ } ,
669+ } )
653670 } else {
654671 let s = TapState {
655672 pointer_id : pointer. pointer_id ,
@@ -660,34 +677,39 @@ impl TapCounter {
660677 y : state. position . y ,
661678 } ;
662679 self . taps . push ( s) ;
663- PointerEvent :: Down {
680+ PointerEvent :: Down ( PointerButtonEvent {
664681 button,
665682 pointer,
666- state : PointerState { count : 1 , ..state } ,
667- }
683+ state : PointerState {
684+ count : 1 ,
685+ scale_factor : self . scale_factor ,
686+ ..state
687+ } ,
688+ } )
668689 } ;
669690 self . clear_expired ( state. time ) ;
670691 e
671692 }
672- PointerEvent :: Up {
693+ PointerEvent :: Up ( PointerButtonEvent {
673694 button,
674695 pointer,
675696 ref state,
676- } => {
697+ } ) => {
677698 if let Some ( i) = self
678699 . taps
679700 . iter ( )
680701 . position ( |TapState { pointer_id, .. } | * pointer_id == pointer. pointer_id )
681702 {
682703 self . taps [ i] . up_time = state. time ;
683- PointerEvent :: Up {
704+ PointerEvent :: Up ( PointerButtonEvent {
684705 button,
685706 pointer,
686707 state : PointerState {
687708 count : self . taps [ i] . count ,
709+ scale_factor : self . scale_factor ,
688710 ..state. clone ( )
689711 } ,
690- }
712+ } )
691713 } else {
692714 e. clone ( )
693715 }
@@ -717,17 +739,26 @@ impl TapCounter {
717739 pointer,
718740 current : PointerState {
719741 count,
742+ scale_factor : self . scale_factor ,
720743 ..current. clone ( )
721744 } ,
722745 coalesced : coalesced
723746 . iter ( )
724747 . cloned ( )
725- . map ( |u| PointerState { count, ..u } )
748+ . map ( |u| PointerState {
749+ count,
750+ scale_factor : self . scale_factor ,
751+ ..u
752+ } )
726753 . collect ( ) ,
727754 predicted : predicted
728755 . iter ( )
729756 . cloned ( )
730- . map ( |u| PointerState { count, ..u } )
757+ . map ( |u| PointerState {
758+ count,
759+ scale_factor : self . scale_factor ,
760+ ..u
761+ } )
731762 . collect ( ) ,
732763 } )
733764 } else {
@@ -739,7 +770,9 @@ impl TapCounter {
739770 . retain ( |TapState { pointer_id, .. } | * pointer_id != p. pointer_id ) ;
740771 e. clone ( )
741772 }
742- PointerEvent :: Enter ( ..) | PointerEvent :: Scroll { .. } => e. clone ( ) ,
773+ PointerEvent :: Enter ( ..) | PointerEvent :: Scroll ( ..) | PointerEvent :: Gesture ( ..) => {
774+ e. clone ( )
775+ }
743776 }
744777 }
745778
0 commit comments