@@ -498,18 +498,27 @@ pub(crate) fn install_canvas_events(runner_ref: &WebRunner) -> Result<(), JsValu
498
498
web_sys:: WheelEvent :: DOM_DELTA_PAGE => egui:: MouseWheelUnit :: Page ,
499
499
_ => return ,
500
500
} ;
501
- // delta sign is flipped to match native (winit) convention.
501
+
502
502
let delta = -egui:: vec2 ( event. delta_x ( ) as f32 , event. delta_y ( ) as f32 ) ;
503
503
504
- // NOTE: pinch-to-zoom on a trackpad will set the `ctrl` modifier on the event,
505
- // even though the user is not holding down ctrl!
506
504
let modifiers = modifiers_from_wheel_event ( & event) ;
507
505
508
- runner. input . raw . events . push ( egui:: Event :: MouseWheel {
509
- unit,
510
- delta,
511
- modifiers,
512
- } ) ;
506
+ if modifiers. ctrl && !runner. input . raw . modifiers . ctrl {
507
+ // The browser is saying the ctrl key is down, but it isn't _really_.
508
+ // This happens on pinch-to-zoom on a Mac trackpad.
509
+ // egui will treat ctrl+scroll as zoom, so it all works.
510
+ // However, we explicitly handle it here in order to better match the pinch-to-zoom
511
+ // speed of a native app, without being sensitive to egui's `scroll_zoom_speed` setting.
512
+ let pinch_to_zoom_sensitivity = 0.01 ; // Feels good on a Mac trackpad in 2024
513
+ let zoom_factor = ( pinch_to_zoom_sensitivity * delta. y ) . exp ( ) ;
514
+ runner. input . raw . events . push ( egui:: Event :: Zoom ( zoom_factor) ) ;
515
+ } else {
516
+ runner. input . raw . events . push ( egui:: Event :: MouseWheel {
517
+ unit,
518
+ delta,
519
+ modifiers,
520
+ } ) ;
521
+ }
513
522
514
523
runner. needs_repaint . repaint_asap ( ) ;
515
524
event. stop_propagation ( ) ;
0 commit comments