Make shift-scroll do horizontal scrolling on all platforms (#1136)
Closes https://github.com/emilk/egui/issues/1135
This commit is contained in:
parent
e4aa1e6e1a
commit
a689b623a6
6 changed files with 21 additions and 4 deletions
|
@ -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)).
|
* 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.
|
* Fix horizontal scrolling direction on Linux.
|
||||||
* Added `App::on_exit_event` ([#1038](https://github.com/emilk/egui/pull/1038))
|
* 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
|
## 0.16.0 - 2021-12-29
|
||||||
|
|
|
@ -6,6 +6,7 @@ All notable changes to the `egui-winit` integration will be noted in this file.
|
||||||
## Unreleased
|
## Unreleased
|
||||||
* Fix horizontal scrolling direction on Linux.
|
* Fix horizontal scrolling direction on Linux.
|
||||||
* Replaced `std::time::Instant` with `instant::Instant` for WebAssembly compatability ([#1023](https://github.com/emilk/egui/pull/1023))
|
* 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
|
## 0.16.0 - 2021-12-29
|
||||||
|
|
|
@ -460,6 +460,12 @@ impl State {
|
||||||
// Treat as zoom instead:
|
// Treat as zoom instead:
|
||||||
let factor = (delta.y / 200.0).exp();
|
let factor = (delta.y / 200.0).exp();
|
||||||
self.egui_input.events.push(egui::Event::Zoom(factor));
|
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 {
|
} else {
|
||||||
self.egui_input.events.push(egui::Event::Scroll(delta));
|
self.egui_input.events.push(egui::Event::Scroll(delta));
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,8 @@ pub enum Event {
|
||||||
/// The direction of the vector indicates how to move the _content_ that is being viewed.
|
/// 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,
|
/// 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.
|
/// 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),
|
Scroll(Vec2),
|
||||||
|
|
||||||
/// Zoom scale factor this frame (e.g. from ctrl-scroll or pinch gesture).
|
/// Zoom scale factor this frame (e.g. from ctrl-scroll or pinch gesture).
|
||||||
|
|
|
@ -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)).
|
* 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)).
|
* 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]).
|
* 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
|
## 0.16.0 - 2021-12-29
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub fn now_sec() -> f64 {
|
||||||
|
|
||||||
pub fn screen_size_in_native_points() -> Option<egui::Vec2> {
|
pub fn screen_size_in_native_points() -> Option<egui::Vec2> {
|
||||||
let window = web_sys::window()?;
|
let window = web_sys::window()?;
|
||||||
Some(egui::Vec2::new(
|
Some(egui::vec2(
|
||||||
window.inner_width().ok()?.as_f64()? as f32,
|
window.inner_width().ok()?.as_f64()? as f32,
|
||||||
window.inner_height().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.
|
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
|
points_per_scroll_line
|
||||||
}
|
}
|
||||||
_ => 1.0,
|
_ => 1.0, // DOM_DELTA_PIXEL
|
||||||
};
|
};
|
||||||
|
|
||||||
let delta = -scroll_multiplier
|
let mut delta =
|
||||||
* egui::Vec2::new(event.delta_x() as f32, event.delta_y() as f32);
|
-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.
|
// 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
|
// 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();
|
let factor = (delta.y / 200.0).exp();
|
||||||
runner_lock.input.raw.events.push(egui::Event::Zoom(factor));
|
runner_lock.input.raw.events.push(egui::Event::Zoom(factor));
|
||||||
} else {
|
} 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
|
runner_lock
|
||||||
.input
|
.input
|
||||||
.raw
|
.raw
|
||||||
|
|
Loading…
Reference in a new issue