Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mac scroll modifier #402

Merged
merged 10 commits into from
May 20, 2021
10 changes: 9 additions & 1 deletion egui_demo_lib/src/apps/demo/plot_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions egui_glium/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion egui_glium/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion egui_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down