1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::Event;
use crate::ScrollDirection;
#[cfg(any(feature = "v4_8", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_8")))]
use crate::ScrollUnit;
use glib::translate::*;
use glib::StaticType;
use std::fmt;
use std::mem;

glib::wrapper! {
    /// An event related to a scrolling motion.
    #[doc(alias = "GdkScrollEvent")]
    pub struct ScrollEvent(Shared<ffi::GdkScrollEvent>);

    match fn {
        ref => |ptr| ffi::gdk_event_ref(ptr as *mut ffi::GdkEvent),
        unref => |ptr| ffi::gdk_event_unref(ptr as *mut ffi::GdkEvent),
    }
}

impl glib::StaticType for ScrollEvent {
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::gdk_scroll_event_get_type()) }
    }
}

impl ScrollEvent {
    /// Extracts the scroll deltas of a scroll event.
    ///
    /// The deltas will be zero unless the scroll direction
    /// is [`ScrollDirection::Smooth`][crate::ScrollDirection::Smooth].
    ///
    /// For the representation unit of these deltas, see
    /// [`unit()`][Self::unit()].
    ///
    /// # Returns
    ///
    ///
    /// ## `delta_x`
    /// return location for x scroll delta
    ///
    /// ## `delta_y`
    /// return location for y scroll delta
    #[doc(alias = "gdk_scroll_event_get_deltas")]
    #[doc(alias = "get_deltas")]
    pub fn deltas(&self) -> (f64, f64) {
        unsafe {
            let mut delta_x = mem::MaybeUninit::uninit();
            let mut delta_y = mem::MaybeUninit::uninit();
            ffi::gdk_scroll_event_get_deltas(
                self.to_glib_none().0,
                delta_x.as_mut_ptr(),
                delta_y.as_mut_ptr(),
            );
            (delta_x.assume_init(), delta_y.assume_init())
        }
    }

    /// Extracts the direction of a scroll event.
    ///
    /// # Returns
    ///
    /// the scroll direction of @self
    #[doc(alias = "gdk_scroll_event_get_direction")]
    #[doc(alias = "get_direction")]
    pub fn direction(&self) -> ScrollDirection {
        unsafe { from_glib(ffi::gdk_scroll_event_get_direction(self.to_glib_none().0)) }
    }

    /// Extracts the scroll delta unit of a scroll event.
    ///
    /// The unit will always be [`ScrollUnit::Wheel`][crate::ScrollUnit::Wheel] if the scroll direction is not
    /// [`ScrollDirection::Smooth`][crate::ScrollDirection::Smooth].
    ///
    /// # Returns
    ///
    /// the scroll unit.
    #[cfg(any(feature = "v4_8", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v4_8")))]
    #[doc(alias = "gdk_scroll_event_get_unit")]
    #[doc(alias = "get_unit")]
    pub fn unit(&self) -> ScrollUnit {
        unsafe { from_glib(ffi::gdk_scroll_event_get_unit(self.to_glib_none().0)) }
    }

    /// Check whether a scroll event is a stop scroll event.
    ///
    /// Scroll sequences with smooth scroll information may provide
    /// a stop scroll event once the interaction with the device finishes,
    /// e.g. by lifting a finger. This stop scroll event is the signal
    /// that a widget may trigger kinetic scrolling based on the current
    /// velocity.
    ///
    /// Stop scroll events always have a delta of 0/0.
    ///
    /// # Returns
    ///
    /// [`true`] if the event is a scroll stop event
    #[doc(alias = "gdk_scroll_event_is_stop")]
    pub fn is_stop(&self) -> bool {
        unsafe { from_glib(ffi::gdk_scroll_event_is_stop(self.to_glib_none().0)) }
    }
}

impl fmt::Display for ScrollEvent {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("ScrollEvent")
    }
}