From f0bab95c4dc13c1989979c611a4663eb5d590a0d Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Fri, 12 Jun 2015 15:32:11 +0100 Subject: Express scroll deltas as either line or pixel deltas Depending on the platform and device, scroll deltas may either be represented as pixel deltas specifying the amount in pixels to scroll or they may be expressed in 'lines' or 'chunks' for low resolution devices (eg. a traditional mouse wheel). Pixel deltas are currently available on OS X. X11 currently supports only integer line deltas, though pixel deltas are available via XInput2. Windows supports fractional line deltas. --- src/events.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/events.rs') diff --git a/src/events.rs b/src/events.rs index 7962706..1103452 100644 --- a/src/events.rs +++ b/src/events.rs @@ -25,11 +25,11 @@ pub enum Event { /// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window. MouseMoved((i32, i32)), - /// Returns the horizontal and vertical mouse scrolling. + /// A mouse wheel or touchpad scroll occurred. Depending on whether the /// /// A positive value indicates that the wheel was rotated forward, away from the user; /// a negative value indicates that the wheel was rotated backward, toward the user. - MouseWheel(f64, f64), + MouseWheel(MouseScrollDelta), /// An event from the mouse has been received. MouseInput(ElementState, MouseButton), @@ -57,6 +57,23 @@ pub enum MouseButton { Other(u8), } +#[derive(Debug, Clone, Copy)] +pub enum MouseScrollDelta { + /// Amount in lines or rows to scroll in the horizontal + /// and vertical directions. + /// + /// Positive values indicate movement forward + /// (away from the user) or righwards. + LineDelta(f32, f32), + /// Amount in pixels to scroll in the horizontal and + /// vertical direction. + /// + /// Scroll events are expressed as a PixelDelta if + /// supported by the device (eg. a touchpad) and + /// platform. + PixelDelta(f32, f32) +} + #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] pub enum VirtualKeyCode { /// The '1' key over the letters. -- cgit v1.2.3 From 5e626b7fdf1942af9c3f1faade1eba6ecd47e0ca Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sat, 13 Jun 2015 23:22:51 +0100 Subject: Correct typo in MouseScrollDelta docs --- src/events.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/events.rs') diff --git a/src/events.rs b/src/events.rs index 1103452..07be8c9 100644 --- a/src/events.rs +++ b/src/events.rs @@ -63,7 +63,7 @@ pub enum MouseScrollDelta { /// and vertical directions. /// /// Positive values indicate movement forward - /// (away from the user) or righwards. + /// (away from the user) or rightwards. LineDelta(f32, f32), /// Amount in pixels to scroll in the horizontal and /// vertical direction. -- cgit v1.2.3 From b2c2f300dce0b874efee4c328629ff9c2316c056 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Mon, 15 Jun 2015 23:54:43 +0100 Subject: Correct MouseWheel doc comment. Remove incomplete sentence and obsolete comment about the meaning of the parameter. --- src/events.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/events.rs') diff --git a/src/events.rs b/src/events.rs index 07be8c9..c175810 100644 --- a/src/events.rs +++ b/src/events.rs @@ -25,10 +25,7 @@ pub enum Event { /// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window. MouseMoved((i32, i32)), - /// A mouse wheel or touchpad scroll occurred. Depending on whether the - /// - /// A positive value indicates that the wheel was rotated forward, away from the user; - /// a negative value indicates that the wheel was rotated backward, toward the user. + /// A mouse wheel movement or touchpad scroll occurred. MouseWheel(MouseScrollDelta), /// An event from the mouse has been received. -- cgit v1.2.3