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