Skip to content

Commit 19b13f1

Browse files
committed
Make shift-scroll do horizontal scrolling on all platforms
Closes #1135
1 parent 76ac41f commit 19b13f1

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

eframe/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ NOTE: [`egui_web`](egui_web/CHANGELOG.md), [`egui-winit`](egui-winit/CHANGELOG.m
1010
* The default web painter is now `egui_glow` (instead of WebGL) ([#1020](https://github.com/emilk/egui/pull/1020)).
1111
* Fix horizontal scrolling direction on Linux.
1212
* Added `App::on_exit_event` ([#1038](https://github.com/emilk/egui/pull/1038))
13+
* Shift-scroll will now result in horizontal scrolling on all platforms ((#1136)[https://github.com/emilk/egui/pull/1136]).
1314

1415

1516
## 0.16.0 - 2021-12-29

egui-winit/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to the `egui-winit` integration will be noted in this file.
66
## Unreleased
77
* Fix horizontal scrolling direction on Linux.
88
* Replaced `std::time::Instant` with `instant::Instant` for WebAssembly compatability ([#1023](https://github.com/emilk/egui/pull/1023))
9+
* Shift-scroll will now result in horizontal scrolling on all platforms ((#1136)[https://github.com/emilk/egui/pull/1136]).
910

1011

1112
## 0.16.0 - 2021-12-29

egui-winit/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,12 @@ impl State {
460460
// Treat as zoom instead:
461461
let factor = (delta.y / 200.0).exp();
462462
self.egui_input.events.push(egui::Event::Zoom(factor));
463+
} else if self.egui_input.modifiers.shift {
464+
// Treat as horizontal scrolling.
465+
// Note: one Mac we already get horizontal scroll events when shift is down.
466+
self.egui_input
467+
.events
468+
.push(egui::Event::Scroll(egui::vec2(delta.x + delta.y, 0.0)));
463469
} else {
464470
self.egui_input.events.push(egui::Event::Scroll(delta));
465471
}

egui/src/data/input.rs

+2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ pub enum Event {
180180
/// The direction of the vector indicates how to move the _content_ that is being viewed.
181181
/// So if you get positive values, the content being viewed should move to the right and down,
182182
/// revealing new things to the left and up.
183+
///
184+
/// Shift-scroll should result in horizontal scrolling (it is up to the integrations to do this).
183185
Scroll(Vec2),
184186

185187
/// Zoom scale factor this frame (e.g. from ctrl-scroll or pinch gesture).

egui_web/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to the `egui_web` integration will be noted in this file.
77
* The default painter is now glow instead of WebGL ([#1020](https://github.com/emilk/egui/pull/1020)).
88
* Made the WebGL painter opt-in ([#1020](https://github.com/emilk/egui/pull/1020)).
99
* Fix glow failure Chrome ((#1092)[https://github.com/emilk/egui/pull/1092]).
10+
* Shift-scroll will now result in horizontal scrolling on all platforms ((#1136)[https://github.com/emilk/egui/pull/1136]).
1011

1112

1213
## 0.16.0 - 2021-12-29

egui_web/src/lib.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn now_sec() -> f64 {
6969

7070
pub fn screen_size_in_native_points() -> Option<egui::Vec2> {
7171
let window = web_sys::window()?;
72-
Some(egui::Vec2::new(
72+
Some(egui::vec2(
7373
window.inner_width().ok()?.as_f64()? as f32,
7474
window.inner_height().ok()?.as_f64()? as f32,
7575
))
@@ -1022,11 +1022,11 @@ fn install_canvas_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
10221022
let points_per_scroll_line = 8.0; // Note that this is intentionally different from what we use in egui_glium / winit.
10231023
points_per_scroll_line
10241024
}
1025-
_ => 1.0,
1025+
_ => 1.0, // DOM_DELTA_PIXEL
10261026
};
10271027

1028-
let delta = -scroll_multiplier
1029-
* egui::Vec2::new(event.delta_x() as f32, event.delta_y() as f32);
1028+
let mut delta =
1029+
-scroll_multiplier * egui::vec2(event.delta_x() as f32, event.delta_y() as f32);
10301030

10311031
// Report a zoom event in case CTRL (on Windows or Linux) or CMD (on Mac) is pressed.
10321032
// 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> {
10351035
let factor = (delta.y / 200.0).exp();
10361036
runner_lock.input.raw.events.push(egui::Event::Zoom(factor));
10371037
} else {
1038+
if event.shift_key() {
1039+
// Treat as horizontal scrolling.
1040+
// Note: one Mac we already get horizontal scroll events when shift is down.
1041+
delta = egui::vec2(delta.x + delta.y, 0.0);
1042+
}
1043+
10381044
runner_lock
10391045
.input
10401046
.raw

0 commit comments

Comments
 (0)