Skip to main content

gtk/auto/
event_controller_motion.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
5use crate::{EventController, Widget};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14    /// [`EventControllerMotion`][crate::EventControllerMotion] is an event controller meant for situations
15    /// where you need to track the position of the pointer.
16    ///
17    /// This object was added in 3.24.
18    ///
19    /// ## Signals
20    ///
21    ///
22    /// #### `enter`
23    ///  Signals that the pointer has entered the widget.
24    ///
25    ///
26    ///
27    ///
28    /// #### `leave`
29    ///  Signals that pointer has left the widget.
30    ///
31    ///
32    ///
33    ///
34    /// #### `motion`
35    ///  Emitted when the pointer moves inside the widget.
36    ///
37    ///
38    ///
39    /// # Implements
40    ///
41    /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
42    #[doc(alias = "GtkEventControllerMotion")]
43    pub struct EventControllerMotion(Object<ffi::GtkEventControllerMotion, ffi::GtkEventControllerMotionClass>) @extends EventController;
44
45    match fn {
46        type_ => || ffi::gtk_event_controller_motion_get_type(),
47    }
48}
49
50impl EventControllerMotion {
51    /// Creates a new event controller that will handle motion events
52    /// for the given `widget`.
53    /// ## `widget`
54    /// a [`Widget`][crate::Widget]
55    ///
56    /// # Returns
57    ///
58    /// a new [`EventControllerMotion`][crate::EventControllerMotion]
59    #[doc(alias = "gtk_event_controller_motion_new")]
60    pub fn new(widget: &impl IsA<Widget>) -> EventControllerMotion {
61        skip_assert_initialized!();
62        unsafe {
63            EventController::from_glib_full(ffi::gtk_event_controller_motion_new(
64                widget.as_ref().to_glib_none().0,
65            ))
66            .unsafe_cast()
67        }
68    }
69
70    /// Signals that the pointer has entered the widget.
71    /// ## `x`
72    /// the x coordinate
73    /// ## `y`
74    /// the y coordinate
75    #[doc(alias = "enter")]
76    pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
77        unsafe extern "C" fn enter_trampoline<F: Fn(&EventControllerMotion, f64, f64) + 'static>(
78            this: *mut ffi::GtkEventControllerMotion,
79            x: libc::c_double,
80            y: libc::c_double,
81            f: glib::ffi::gpointer,
82        ) {
83            let f: &F = &*(f as *const F);
84            f(&from_glib_borrow(this), x, y)
85        }
86        unsafe {
87            let f: Box_<F> = Box_::new(f);
88            connect_raw(
89                self.as_ptr() as *mut _,
90                b"enter\0".as_ptr() as *const _,
91                Some(transmute::<_, unsafe extern "C" fn()>(
92                    enter_trampoline::<F> as *const (),
93                )),
94                Box_::into_raw(f),
95            )
96        }
97    }
98
99    /// Signals that pointer has left the widget.
100    #[doc(alias = "leave")]
101    pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
102        unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerMotion) + 'static>(
103            this: *mut ffi::GtkEventControllerMotion,
104            f: glib::ffi::gpointer,
105        ) {
106            let f: &F = &*(f as *const F);
107            f(&from_glib_borrow(this))
108        }
109        unsafe {
110            let f: Box_<F> = Box_::new(f);
111            connect_raw(
112                self.as_ptr() as *mut _,
113                b"leave\0".as_ptr() as *const _,
114                Some(transmute::<_, unsafe extern "C" fn()>(
115                    leave_trampoline::<F> as *const (),
116                )),
117                Box_::into_raw(f),
118            )
119        }
120    }
121
122    /// Emitted when the pointer moves inside the widget.
123    /// ## `x`
124    /// the x coordinate
125    /// ## `y`
126    /// the y coordinate
127    #[doc(alias = "motion")]
128    pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
129        unsafe extern "C" fn motion_trampoline<
130            F: Fn(&EventControllerMotion, f64, f64) + 'static,
131        >(
132            this: *mut ffi::GtkEventControllerMotion,
133            x: libc::c_double,
134            y: libc::c_double,
135            f: glib::ffi::gpointer,
136        ) {
137            let f: &F = &*(f as *const F);
138            f(&from_glib_borrow(this), x, y)
139        }
140        unsafe {
141            let f: Box_<F> = Box_::new(f);
142            connect_raw(
143                self.as_ptr() as *mut _,
144                b"motion\0".as_ptr() as *const _,
145                Some(transmute::<_, unsafe extern "C" fn()>(
146                    motion_trampoline::<F> as *const (),
147                )),
148                Box_::into_raw(f),
149            )
150        }
151    }
152}
153
154impl fmt::Display for EventControllerMotion {
155    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
156        f.write_str("EventControllerMotion")
157    }
158}