summaryrefslogtreecommitdiffstats
path: root/widget/src/scrollable.rs
diff options
context:
space:
mode:
authorLibravatar Matt Woelfel <matt@woelfware.com>2024-05-13 21:16:19 -0500
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-08 19:03:31 +0200
commit0a0ea30059b86ca70951aff535c078c1c4b2af0e (patch)
treeb28c251289bf65a553a76a4abbb0e51cabbb6b4e /widget/src/scrollable.rs
parentc8686c5173a93454f3fe1e6c287d312a9b9f13c5 (diff)
downloadiced-0a0ea30059b86ca70951aff535c078c1c4b2af0e.tar.gz
iced-0a0ea30059b86ca70951aff535c078c1c4b2af0e.tar.bz2
iced-0a0ea30059b86ca70951aff535c078c1c4b2af0e.zip
Enable horizontal scrolling without shift modifier
Fixes #2359.
Diffstat (limited to '')
-rw-r--r--widget/src/scrollable.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs
index 47953741..c2089340 100644
--- a/widget/src/scrollable.rs
+++ b/widget/src/scrollable.rs
@@ -706,15 +706,29 @@ where
let delta = match delta {
mouse::ScrollDelta::Lines { x, y } => {
- // TODO: Configurable speed/friction (?)
- let movement = if !cfg!(target_os = "macos") // macOS automatically inverts the axes when Shift is pressed
- && state.keyboard_modifiers.shift()
- {
- Vector::new(y, x)
- } else {
+ let is_shift_pressed = state.keyboard_modifiers.shift();
+
+ // macOS automatically inverts the axes when Shift is pressed
+ let (x, y) =
+ if cfg!(target_os = "macos") && is_shift_pressed {
+ (y, x)
+ } else {
+ (x, y)
+ };
+
+ let is_vertical = match self.direction {
+ Direction::Vertical(_) => true,
+ Direction::Horizontal(_) => false,
+ Direction::Both { .. } => !is_shift_pressed,
+ };
+
+ let movement = if is_vertical {
Vector::new(x, y)
+ } else {
+ Vector::new(y, x)
};
+ // TODO: Configurable speed/friction (?)
movement * 60.0
}
mouse::ScrollDelta::Pixels { x, y } => Vector::new(x, y),