diff options
-rw-r--r-- | native/src/input/mouse.rs | 2 | ||||
-rw-r--r-- | native/src/input/mouse/event.rs | 17 | ||||
-rw-r--r-- | native/src/widget/scrollable.rs | 15 | ||||
-rw-r--r-- | winit/src/application.rs | 23 |
4 files changed, 46 insertions, 11 deletions
diff --git a/native/src/input/mouse.rs b/native/src/input/mouse.rs index d37f5b96..69dc6b4c 100644 --- a/native/src/input/mouse.rs +++ b/native/src/input/mouse.rs @@ -3,4 +3,4 @@ mod button; mod event; pub use button::Button; -pub use event::Event; +pub use event::{Event, ScrollDelta}; diff --git a/native/src/input/mouse/event.rs b/native/src/input/mouse/event.rs index 7b68208f..478f9b4d 100644 --- a/native/src/input/mouse/event.rs +++ b/native/src/input/mouse/event.rs @@ -34,11 +34,22 @@ pub enum Event { }, /// The mouse wheel was scrolled. - WheelScrolled { + WheelScrolled { delta: ScrollDelta }, +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum ScrollDelta { + Lines { /// The number of horizontal lines scrolled - delta_x: f32, + x: f32, /// The number of vertical lines scrolled - delta_y: f32, + y: f32, + }, + Pixels { + /// The number of horizontal pixels scrolled + x: f32, + /// The number of vertical pixels scrolled + y: f32, }, } diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 76d12124..8a82be4f 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -64,11 +64,16 @@ where // TODO: Event capture. Nested scrollables should capture scroll events. if is_mouse_over { match event { - Event::Mouse(mouse::Event::WheelScrolled { - delta_y, .. - }) => { - // TODO: Configurable speed (?) - self.state.scroll(delta_y * 15.0, bounds, content_bounds); + Event::Mouse(mouse::Event::WheelScrolled { delta }) => { + match delta { + mouse::ScrollDelta::Lines { y, .. } => { + // TODO: Configurable speed (?) + self.state.scroll(y * 15.0, bounds, content_bounds); + } + mouse::ScrollDelta::Pixels { y, .. } => { + self.state.scroll(y, bounds, content_bounds); + } + } } _ => {} } diff --git a/winit/src/application.rs b/winit/src/application.rs index 855968aa..c8748199 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -123,6 +123,7 @@ pub trait Application { .. } => match window_event { WindowEvent::CursorMoved { position, .. } => { + // TODO: Remove when renderer supports HiDPI let physical_position = position.to_physical(window.hidpi_factor()); @@ -143,10 +144,28 @@ pub trait Application { delta_y, ) => { events.push(Event::Mouse( - mouse::Event::WheelScrolled { delta_x, delta_y }, + mouse::Event::WheelScrolled { + delta: mouse::ScrollDelta::Lines { + x: delta_x, + y: delta_y, + }, + }, + )); + } + winit::event::MouseScrollDelta::PixelDelta(position) => { + // TODO: Remove when renderer supports HiDPI + let physical_position = + position.to_physical(window.hidpi_factor()); + + events.push(Event::Mouse( + mouse::Event::WheelScrolled { + delta: mouse::ScrollDelta::Pixels { + x: physical_position.x as f32, + y: physical_position.y as f32, + }, + }, )); } - _ => {} }, WindowEvent::CloseRequested => { *control_flow = ControlFlow::Exit; |