From a689b623a669d54ea85708a8c748eb07e23754b0 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 21 Jan 2022 10:48:44 +0100 Subject: [PATCH] Make shift-scroll do horizontal scrolling on all platforms (#1136) Closes https://github.com/emilk/egui/issues/1135 --- eframe/CHANGELOG.md | 1 + egui-winit/CHANGELOG.md | 1 + egui-winit/src/lib.rs | 6 ++++++ egui/src/data/input.rs | 2 ++ egui_web/CHANGELOG.md | 1 + egui_web/src/lib.rs | 14 ++++++++++---- 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/eframe/CHANGELOG.md b/eframe/CHANGELOG.md index d236aac5..81ef7ae6 100644 --- a/eframe/CHANGELOG.md +++ b/eframe/CHANGELOG.md @@ -10,6 +10,7 @@ NOTE: [`egui_web`](egui_web/CHANGELOG.md), [`egui-winit`](egui-winit/CHANGELOG.m * The default web painter is now `egui_glow` (instead of WebGL) ([#1020](https://github.com/emilk/egui/pull/1020)). * Fix horizontal scrolling direction on Linux. * Added `App::on_exit_event` ([#1038](https://github.com/emilk/egui/pull/1038)) +* Shift-scroll will now result in horizontal scrolling on all platforms ((#1136)[https://github.com/emilk/egui/pull/1136]). ## 0.16.0 - 2021-12-29 diff --git a/egui-winit/CHANGELOG.md b/egui-winit/CHANGELOG.md index d6d04c13..55d50bda 100644 --- a/egui-winit/CHANGELOG.md +++ b/egui-winit/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to the `egui-winit` integration will be noted in this file. ## Unreleased * Fix horizontal scrolling direction on Linux. * Replaced `std::time::Instant` with `instant::Instant` for WebAssembly compatability ([#1023](https://github.com/emilk/egui/pull/1023)) +* Shift-scroll will now result in horizontal scrolling on all platforms ((#1136)[https://github.com/emilk/egui/pull/1136]). ## 0.16.0 - 2021-12-29 diff --git a/egui-winit/src/lib.rs b/egui-winit/src/lib.rs index 0b91d1d5..69c15c1b 100644 --- a/egui-winit/src/lib.rs +++ b/egui-winit/src/lib.rs @@ -460,6 +460,12 @@ impl State { // Treat as zoom instead: let factor = (delta.y / 200.0).exp(); self.egui_input.events.push(egui::Event::Zoom(factor)); + } else if self.egui_input.modifiers.shift { + // Treat as horizontal scrolling. + // Note: one Mac we already get horizontal scroll events when shift is down. + self.egui_input + .events + .push(egui::Event::Scroll(egui::vec2(delta.x + delta.y, 0.0))); } else { self.egui_input.events.push(egui::Event::Scroll(delta)); } diff --git a/egui/src/data/input.rs b/egui/src/data/input.rs index 6465ec2f..6de259a2 100644 --- a/egui/src/data/input.rs +++ b/egui/src/data/input.rs @@ -180,6 +180,8 @@ pub enum Event { /// The direction of the vector indicates how to move the _content_ that is being viewed. /// So if you get positive values, the content being viewed should move to the right and down, /// revealing new things to the left and up. + /// + /// Shift-scroll should result in horizontal scrolling (it is up to the integrations to do this). Scroll(Vec2), /// Zoom scale factor this frame (e.g. from ctrl-scroll or pinch gesture). diff --git a/egui_web/CHANGELOG.md b/egui_web/CHANGELOG.md index 78403a8c..000b3487 100644 --- a/egui_web/CHANGELOG.md +++ b/egui_web/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to the `egui_web` integration will be noted in this file. * The default painter is now glow instead of WebGL ([#1020](https://github.com/emilk/egui/pull/1020)). * Made the WebGL painter opt-in ([#1020](https://github.com/emilk/egui/pull/1020)). * Fix glow failure Chrome ((#1092)[https://github.com/emilk/egui/pull/1092]). +* Shift-scroll will now result in horizontal scrolling on all platforms ((#1136)[https://github.com/emilk/egui/pull/1136]). ## 0.16.0 - 2021-12-29 diff --git a/egui_web/src/lib.rs b/egui_web/src/lib.rs index 99dd305d..dbdb87b4 100644 --- a/egui_web/src/lib.rs +++ b/egui_web/src/lib.rs @@ -69,7 +69,7 @@ pub fn now_sec() -> f64 { pub fn screen_size_in_native_points() -> Option { let window = web_sys::window()?; - Some(egui::Vec2::new( + Some(egui::vec2( window.inner_width().ok()?.as_f64()? as f32, window.inner_height().ok()?.as_f64()? as f32, )) @@ -1022,11 +1022,11 @@ fn install_canvas_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> { let points_per_scroll_line = 8.0; // Note that this is intentionally different from what we use in egui_glium / winit. points_per_scroll_line } - _ => 1.0, + _ => 1.0, // DOM_DELTA_PIXEL }; - let delta = -scroll_multiplier - * egui::Vec2::new(event.delta_x() as f32, event.delta_y() as f32); + let mut delta = + -scroll_multiplier * egui::vec2(event.delta_x() as f32, event.delta_y() as f32); // 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 @@ -1035,6 +1035,12 @@ fn install_canvas_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> { let factor = (delta.y / 200.0).exp(); runner_lock.input.raw.events.push(egui::Event::Zoom(factor)); } else { + if event.shift_key() { + // Treat as horizontal scrolling. + // Note: one Mac we already get horizontal scroll events when shift is down. + delta = egui::vec2(delta.x + delta.y, 0.0); + } + runner_lock .input .raw