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>
This commit is contained in:
Ivo Vollrath 2021-05-20 19:56:33 +02:00 committed by GitHub
parent 5bc53ce069
commit 67c6002578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View file

@ -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 {

View file

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

View file

@ -188,7 +188,7 @@ pub fn input_to_egui(
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:
input_state.raw.zoom_delta *= (delta.y / 200.0).exp();
} else {

View file

@ -1053,7 +1053,10 @@ fn install_canvas_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
let delta = -scroll_multiplier
* 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();
} else {
runner_lock.input.raw.scroll_delta += delta;