gdk4/auto/
scroll_event.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v4_20")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
7use crate::ScrollRelativeDirection;
8#[cfg(feature = "v4_8")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
10use crate::ScrollUnit;
11use crate::{ffi, ScrollDirection};
12use glib::{prelude::*, translate::*};
13
14glib::wrapper! {
15    /// An event related to a scrolling motion.
16    #[doc(alias = "GdkScrollEvent")]
17    pub struct ScrollEvent(Shared<ffi::GdkScrollEvent>);
18
19    match fn {
20        ref => |ptr| ffi::gdk_event_ref(ptr as *mut ffi::GdkEvent),
21        unref => |ptr| ffi::gdk_event_unref(ptr as *mut ffi::GdkEvent),
22    }
23}
24
25impl StaticType for ScrollEvent {
26    fn static_type() -> glib::Type {
27        unsafe { from_glib(ffi::gdk_scroll_event_get_type()) }
28    }
29}
30
31impl ScrollEvent {
32    /// Extracts the scroll deltas of a scroll event.
33    ///
34    /// The deltas will be zero unless the scroll direction
35    /// is [`ScrollDirection::Smooth`][crate::ScrollDirection::Smooth].
36    ///
37    /// For the representation unit of these deltas, see
38    /// [`unit()`][Self::unit()].
39    ///
40    /// # Returns
41    ///
42    ///
43    /// ## `delta_x`
44    /// return location for x scroll delta
45    ///
46    /// ## `delta_y`
47    /// return location for y scroll delta
48    #[doc(alias = "gdk_scroll_event_get_deltas")]
49    #[doc(alias = "get_deltas")]
50    pub fn deltas(&self) -> (f64, f64) {
51        unsafe {
52            let mut delta_x = std::mem::MaybeUninit::uninit();
53            let mut delta_y = std::mem::MaybeUninit::uninit();
54            ffi::gdk_scroll_event_get_deltas(
55                self.to_glib_none().0,
56                delta_x.as_mut_ptr(),
57                delta_y.as_mut_ptr(),
58            );
59            (delta_x.assume_init(), delta_y.assume_init())
60        }
61    }
62
63    /// Extracts the direction of a scroll event.
64    ///
65    /// # Returns
66    ///
67    /// the scroll direction of @self
68    #[doc(alias = "gdk_scroll_event_get_direction")]
69    #[doc(alias = "get_direction")]
70    pub fn direction(&self) -> ScrollDirection {
71        unsafe { from_glib(ffi::gdk_scroll_event_get_direction(self.to_glib_none().0)) }
72    }
73
74    /// Extracts the scroll direction relative to the physical motion.
75    ///
76    /// # Returns
77    ///
78    /// the relative scroll direction.
79    #[cfg(feature = "v4_20")]
80    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
81    #[doc(alias = "gdk_scroll_event_get_relative_direction")]
82    #[doc(alias = "get_relative_direction")]
83    pub fn relative_direction(&self) -> ScrollRelativeDirection {
84        unsafe {
85            from_glib(ffi::gdk_scroll_event_get_relative_direction(
86                self.to_glib_none().0,
87            ))
88        }
89    }
90
91    /// Extracts the scroll delta unit of a scroll event.
92    ///
93    /// The unit will always be [`ScrollUnit::Wheel`][crate::ScrollUnit::Wheel] if the scroll direction is not
94    /// [`ScrollDirection::Smooth`][crate::ScrollDirection::Smooth].
95    ///
96    /// # Returns
97    ///
98    /// the scroll unit.
99    #[cfg(feature = "v4_8")]
100    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
101    #[doc(alias = "gdk_scroll_event_get_unit")]
102    #[doc(alias = "get_unit")]
103    pub fn unit(&self) -> ScrollUnit {
104        unsafe { from_glib(ffi::gdk_scroll_event_get_unit(self.to_glib_none().0)) }
105    }
106
107    /// Check whether a scroll event is a stop scroll event.
108    ///
109    /// Scroll sequences with smooth scroll information may provide
110    /// a stop scroll event once the interaction with the device finishes,
111    /// e.g. by lifting a finger. This stop scroll event is the signal
112    /// that a widget may trigger kinetic scrolling based on the current
113    /// velocity.
114    ///
115    /// Stop scroll events always have a delta of 0/0.
116    ///
117    /// # Returns
118    ///
119    /// [`true`] if the event is a scroll stop event
120    #[doc(alias = "gdk_scroll_event_is_stop")]
121    pub fn is_stop(&self) -> bool {
122        unsafe { from_glib(ffi::gdk_scroll_event_is_stop(self.to_glib_none().0)) }
123    }
124}