Browse Source

Fix mac scroll modifier (#402)

* fix modifier key for mouse wheel zoom

* update CHANGELOG

* fix zoom modifier for web backend

* improve instructions in plot demo window

* accept emilk's proposed change

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* update UI instructions for Plot demo

* improve UI instructions for plot demo

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
pull/432/head
Ivo Vollrath 4 years ago
committed by GitHub
parent
commit
67c6002578
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      egui_demo_lib/src/apps/demo/plot_demo.rs
  2. 1
      egui_glium/CHANGELOG.md
  3. 2
      egui_glium/src/lib.rs
  4. 5
      egui_web/src/lib.rs

10
egui_demo_lib/src/apps/demo/plot_demo.rs

@ -95,7 +95,15 @@ impl PlotDemo {
}); });
}); });
ui.label("Drag to pan, ctrl + scroll to zoom. Double-click to reset view."); ui.label("Pan by dragging, or scroll (+ shift = horizontal).");
if cfg!(target_arch = "wasm32") {
ui.label("Zoom with ctrl / ⌘ + mouse wheel, or with pinch gesture.");
} else if cfg!(target_os = "macos") {
ui.label("Zoom with ctrl / ⌘ + scroll.");
} else {
ui.label("Zoom with ctrl + scroll.");
}
ui.label("Reset view with double-click.");
} }
fn circle(&self) -> Curve { fn circle(&self) -> Curve {

1
egui_glium/CHANGELOG.md

@ -5,6 +5,7 @@ All notable changes to the `egui_glium` integration will be noted in this file.
## Unreleased ## Unreleased
* [Fix modifier key for zoom with mouse wheel on Mac](https://github.com/emilk/egui/issues/401)
## 0.12.0 - 2021-05-10 ## 0.12.0 - 2021-05-10

2
egui_glium/src/lib.rs

@ -188,7 +188,7 @@ pub fn input_to_egui(
delta.x *= -1.0; delta.x *= -1.0;
} }
if input_state.raw.modifiers.ctrl { if input_state.raw.modifiers.ctrl || input_state.raw.modifiers.command {
// Treat as zoom instead: // Treat as zoom instead:
input_state.raw.zoom_delta *= (delta.y / 200.0).exp(); input_state.raw.zoom_delta *= (delta.y / 200.0).exp();
} else { } else {

5
egui_web/src/lib.rs

@ -1053,7 +1053,10 @@ fn install_canvas_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
let delta = -scroll_multiplier let delta = -scroll_multiplier
* egui::Vec2::new(event.delta_x() as f32, event.delta_y() as f32); * egui::Vec2::new(event.delta_x() as f32, event.delta_y() as f32);
if event.ctrl_key() { // Report a zoom event in case CTRL (on Windows or Linux) or CMD (on Mac) is pressed.
// This if-statement is equivalent to how `Modifiers.command` is determined in
// `modifiers_from_event()`, but we cannot directly use that fn for a `WheelEvent`.
if event.ctrl_key() || event.meta_key() {
runner_lock.input.raw.zoom_delta *= (delta.y / 200.0).exp(); runner_lock.input.raw.zoom_delta *= (delta.y / 200.0).exp();
} else { } else {
runner_lock.input.raw.scroll_delta += delta; runner_lock.input.raw.scroll_delta += delta;

Loading…
Cancel
Save