Enable horizontal scrolling with Shift+MouseWheel

This commit is contained in:
Héctor Ramón Jiménez 2023-01-08 20:17:11 +01:00
parent 0c2bcecd44
commit 19f4373863
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -1,5 +1,6 @@
//! Navigate an endless amount of content with a scrollbar. //! Navigate an endless amount of content with a scrollbar.
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::keyboard;
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
use crate::overlay; use crate::overlay;
@ -479,13 +480,26 @@ pub fn update<Message>(
return event::Status::Captured; return event::Status::Captured;
} }
if let Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) = event
{
state.keyboard_modifiers = modifiers;
return event::Status::Ignored;
}
if mouse_over_scrollable { if mouse_over_scrollable {
match event { match event {
Event::Mouse(mouse::Event::WheelScrolled { delta }) => { Event::Mouse(mouse::Event::WheelScrolled { delta }) => {
let delta = match delta { let delta = match delta {
mouse::ScrollDelta::Lines { x, y } => { mouse::ScrollDelta::Lines { x, y } => {
// TODO: Configurable speed/friction (?) // TODO: Configurable speed/friction (?)
Vector::new(x * 60.0, y * 60.0) let movement = if state.keyboard_modifiers.shift() {
Vector::new(y, x)
} else {
Vector::new(x, y)
};
movement * 60.0
} }
mouse::ScrollDelta::Pixels { x, y } => Vector::new(x, y), mouse::ScrollDelta::Pixels { x, y } => Vector::new(x, y),
}; };
@ -906,6 +920,7 @@ pub struct State {
y_scroller_grabbed_at: Option<f32>, y_scroller_grabbed_at: Option<f32>,
offset_x: Offset, offset_x: Offset,
x_scroller_grabbed_at: Option<f32>, x_scroller_grabbed_at: Option<f32>,
keyboard_modifiers: keyboard::Modifiers,
} }
impl Default for State { impl Default for State {
@ -916,6 +931,7 @@ impl Default for State {
y_scroller_grabbed_at: None, y_scroller_grabbed_at: None,
offset_x: Offset::Absolute(0.0), offset_x: Offset::Absolute(0.0),
x_scroller_grabbed_at: None, x_scroller_grabbed_at: None,
keyboard_modifiers: keyboard::Modifiers::default(),
} }
} }
} }