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