Skip to main content

gdk/
event_scroll.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ffi;
4use glib::translate::*;
5
6/// Generated from button presses for the buttons 4 to 7. Wheel mice are
7/// usually configured to generate button press events for buttons 4 and 5
8/// when the wheel is turned.
9///
10/// Some GDK backends can also generate “smooth” scroll events, which
11/// can be recognized by the [`ScrollDirection::Smooth`][crate::ScrollDirection::Smooth] scroll direction. For
12/// these, the scroll deltas can be obtained with
13/// `gdk_event_get_scroll_deltas()`.
14#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
15pub struct EventScroll(crate::Event);
16
17event_wrapper!(EventScroll, GdkEventScroll);
18event_subtype!(EventScroll, ffi::GDK_SCROLL);
19
20impl EventScroll {
21    #[doc(alias = "get_time")]
22    pub fn time(&self) -> u32 {
23        self.as_ref().time
24    }
25
26    #[doc(alias = "get_position")]
27    pub fn position(&self) -> (f64, f64) {
28        let x = self.as_ref().x;
29        let y = self.as_ref().y;
30        (x, y)
31    }
32
33    #[doc(alias = "get_state")]
34    pub fn state(&self) -> crate::ModifierType {
35        unsafe { from_glib(self.as_ref().state) }
36    }
37
38    #[doc(alias = "get_device")]
39    pub fn device(&self) -> Option<crate::Device> {
40        unsafe { from_glib_none(self.as_ref().device) }
41    }
42
43    #[doc(alias = "get_direction")]
44    pub fn direction(&self) -> crate::ScrollDirection {
45        unsafe { from_glib(self.as_ref().direction) }
46    }
47
48    #[doc(alias = "get_root")]
49    pub fn root(&self) -> (f64, f64) {
50        let x_root = self.as_ref().x_root;
51        let y_root = self.as_ref().y_root;
52        (x_root, y_root)
53    }
54
55    #[doc(alias = "get_delta")]
56    pub fn delta(&self) -> (f64, f64) {
57        let dx = self.as_ref().delta_x;
58        let dy = self.as_ref().delta_y;
59        (dx, dy)
60    }
61
62    #[doc(alias = "get_is_stop")]
63    pub fn is_stop(&self) -> bool {
64        self.as_ref().is_stop & 1 != 0
65    }
66}