@@ -10,9 +10,9 @@ use vello::kurbo::{Point, Size, Vec2};
1010
1111use crate :: core:: keyboard:: { Key , KeyState , NamedKey } ;
1212use crate :: core:: {
13- AccessCtx , AccessEvent , BoxConstraints , ChildrenIds , ComposeCtx , EventCtx , LayoutCtx ,
14- NewWidget , PaintCtx , PointerEvent , PropertiesMut , PropertiesRef , RegisterCtx , ScrollDelta ,
15- TextEvent , Update , UpdateCtx , Widget , WidgetMut , WidgetPod ,
13+ AccessCtx , AccessEvent , BoxConstraints , ChildrenIds , ComposeCtx , EventCtx , KeyboardEvent ,
14+ LayoutCtx , NewWidget , PaintCtx , PointerEvent , PointerScrollEvent , PropertiesMut , PropertiesRef ,
15+ RegisterCtx , ScrollDelta , TextEvent , Update , UpdateCtx , Widget , WidgetMut , WidgetPod ,
1616} ;
1717use crate :: util:: debug_panic;
1818
@@ -524,10 +524,10 @@ impl Widget for VirtualScroll {
524524 event : & PointerEvent ,
525525 ) {
526526 match event {
527- PointerEvent :: Scroll ( s ) => {
527+ PointerEvent :: Scroll ( PointerScrollEvent { delta , .. } ) => {
528528 // TODO - Remove reference to scale factor.
529529 // See https://github.com/linebender/xilem/issues/1264
530- let delta = match s . delta {
530+ let delta = match delta {
531531 ScrollDelta :: PixelDelta ( p) => -p. to_logical :: < f64 > ( ctx. get_scale_factor ( ) ) . y ,
532532 ScrollDelta :: LineDelta ( _, y) => -y as f64 * ctx. get_scale_factor ( ) * 120. ,
533533 _ => 0.0 ,
@@ -545,23 +545,33 @@ impl Widget for VirtualScroll {
545545 _props : & mut PropertiesMut < ' _ > ,
546546 event : & TextEvent ,
547547 ) {
548- match event {
549- TextEvent :: Keyboard ( key_event) => {
550- // To get to this state, you currently need to press "tab" to focus this widget in the example.
551- if matches ! ( key_event. state, KeyState :: Down ) {
552- // We use an unreasonably large delta (logical pixels) here to allow testing that the case where the
553- // scrolling "jumps" the area is handled correctly.
554- // In future, this manual testing would be achieved through use of a scrollbar.
555- let delta = 20000. ;
556- if matches ! ( key_event. key, Key :: Named ( NamedKey :: PageDown ) ) {
557- self . scroll_offset_from_anchor += delta;
558- self . event_post_scroll ( ctx) ;
559- }
560- if matches ! ( key_event. key, Key :: Named ( NamedKey :: PageUp ) ) {
561- self . scroll_offset_from_anchor -= delta;
562- self . event_post_scroll ( ctx) ;
563- }
564- }
548+ // We use an unreasonably large delta (logical pixels) here to allow testing that the case
549+ // where the scrolling "jumps" the area is handled correctly.
550+ // In future, this manual testing would be achieved through use of a scrollbar.
551+ const DELTA : f64 = 20000. ;
552+
553+ // To get to this state, you currently need to press "tab" to focus this widget in the
554+ // example.
555+ let TextEvent :: Keyboard ( keyboard_event) = event else {
556+ return ;
557+ } ;
558+
559+ match keyboard_event {
560+ KeyboardEvent {
561+ state : KeyState :: Down ,
562+ key : Key :: Named ( NamedKey :: PageDown ) ,
563+ ..
564+ } => {
565+ self . scroll_offset_from_anchor += DELTA ;
566+ self . event_post_scroll ( ctx) ;
567+ }
568+ KeyboardEvent {
569+ state : KeyState :: Down ,
570+ key : Key :: Named ( NamedKey :: PageUp ) ,
571+ ..
572+ } => {
573+ self . scroll_offset_from_anchor -= DELTA ;
574+ self . event_post_scroll ( ctx) ;
565575 }
566576 _ => { }
567577 }
0 commit comments