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_8")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
7use crate::ScrollUnit;
8use crate::{ffi, ScrollDirection};
9#[cfg(feature = "v4_20")]
10#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
11use crate::{Event, ScrollRelativeDirection};
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 delta unit of a scroll event.
75    ///
76    /// The unit will always be [`ScrollUnit::Wheel`][crate::ScrollUnit::Wheel] if the scroll direction is not
77    /// [`ScrollDirection::Smooth`][crate::ScrollDirection::Smooth].
78    ///
79    /// # Returns
80    ///
81    /// the scroll unit.
82    #[cfg(feature = "v4_8")]
83    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
84    #[doc(alias = "gdk_scroll_event_get_unit")]
85    #[doc(alias = "get_unit")]
86    pub fn unit(&self) -> ScrollUnit {
87        unsafe { from_glib(ffi::gdk_scroll_event_get_unit(self.to_glib_none().0)) }
88    }
89
90    /// Check whether a scroll event is a stop scroll event.
91    ///
92    /// Scroll sequences with smooth scroll information may provide
93    /// a stop scroll event once the interaction with the device finishes,
94    /// e.g. by lifting a finger. This stop scroll event is the signal
95    /// that a widget may trigger kinetic scrolling based on the current
96    /// velocity.
97    ///
98    /// Stop scroll events always have a delta of 0/0.
99    ///
100    /// # Returns
101    ///
102    /// [`true`] if the event is a scroll stop event
103    #[doc(alias = "gdk_scroll_event_is_stop")]
104    pub fn is_stop(&self) -> bool {
105        unsafe { from_glib(ffi::gdk_scroll_event_is_stop(self.to_glib_none().0)) }
106    }
107
108    #[cfg(feature = "v4_20")]
109    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
110    #[doc(alias = "gdk_scroll_event_get_relative_direction")]
111    #[doc(alias = "get_relative_direction")]
112    pub fn relative_direction(event: impl AsRef<Event>) -> ScrollRelativeDirection {
113        skip_assert_initialized!();
114        unsafe {
115            from_glib(ffi::gdk_scroll_event_get_relative_direction(
116                event.as_ref().to_glib_none().0,
117            ))
118        }
119    }
120}