gdk4/auto/
scroll_event.rs1#[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 #[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 #[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 #[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 #[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 #[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}