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")]
16 pub struct ScrollEvent(Shared<ffi::GdkScrollEvent>);
17
18 match fn {
19 ref => |ptr| ffi::gdk_event_ref(ptr as *mut ffi::GdkEvent),
20 unref => |ptr| ffi::gdk_event_unref(ptr as *mut ffi::GdkEvent),
21 }
22}
23
24impl StaticType for ScrollEvent {
25 fn static_type() -> glib::Type {
26 unsafe { from_glib(ffi::gdk_scroll_event_get_type()) }
27 }
28}
29
30impl ScrollEvent {
31 #[doc(alias = "gdk_scroll_event_get_deltas")]
32 #[doc(alias = "get_deltas")]
33 pub fn deltas(&self) -> (f64, f64) {
34 unsafe {
35 let mut delta_x = std::mem::MaybeUninit::uninit();
36 let mut delta_y = std::mem::MaybeUninit::uninit();
37 ffi::gdk_scroll_event_get_deltas(
38 self.to_glib_none().0,
39 delta_x.as_mut_ptr(),
40 delta_y.as_mut_ptr(),
41 );
42 (delta_x.assume_init(), delta_y.assume_init())
43 }
44 }
45
46 #[doc(alias = "gdk_scroll_event_get_direction")]
47 #[doc(alias = "get_direction")]
48 pub fn direction(&self) -> ScrollDirection {
49 unsafe { from_glib(ffi::gdk_scroll_event_get_direction(self.to_glib_none().0)) }
50 }
51
52 #[cfg(feature = "v4_8")]
53 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
54 #[doc(alias = "gdk_scroll_event_get_unit")]
55 #[doc(alias = "get_unit")]
56 pub fn unit(&self) -> ScrollUnit {
57 unsafe { from_glib(ffi::gdk_scroll_event_get_unit(self.to_glib_none().0)) }
58 }
59
60 #[doc(alias = "gdk_scroll_event_is_stop")]
61 pub fn is_stop(&self) -> bool {
62 unsafe { from_glib(ffi::gdk_scroll_event_is_stop(self.to_glib_none().0)) }
63 }
64
65 #[cfg(feature = "v4_20")]
66 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
67 #[doc(alias = "gdk_scroll_event_get_relative_direction")]
68 #[doc(alias = "get_relative_direction")]
69 pub fn relative_direction(event: impl AsRef<Event>) -> ScrollRelativeDirection {
70 skip_assert_initialized!();
71 unsafe {
72 from_glib(ffi::gdk_scroll_event_get_relative_direction(
73 event.as_ref().to_glib_none().0,
74 ))
75 }
76 }
77}