Skip to main content

gtk4/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, PropagationLimit, PropagationPhase, 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    /// Tracks the pointer position.
16    ///
17    /// The event controller offers [`enter`][struct@crate::EventControllerMotion#enter]
18    /// and [`leave`][struct@crate::EventControllerMotion#leave] signals, as well as
19    /// [`is-pointer`][struct@crate::EventControllerMotion#is-pointer] and
20    /// [`contains-pointer`][struct@crate::EventControllerMotion#contains-pointer] properties
21    /// which are updated to reflect changes in the pointer position as it
22    /// moves over the widget.
23    ///
24    /// ## Properties
25    ///
26    ///
27    /// #### `contains-pointer`
28    ///  Whether the pointer is in the controllers widget or a descendant.
29    ///
30    /// See also [`is-pointer`][struct@crate::EventControllerMotion#is-pointer].
31    ///
32    /// When handling crossing events, this property is updated
33    /// before [`enter`][struct@crate::EventControllerMotion#enter], but after
34    /// [`leave`][struct@crate::EventControllerMotion#leave] is emitted.
35    ///
36    /// Readable
37    ///
38    ///
39    /// #### `is-pointer`
40    ///  Whether the pointer is in the controllers widget itself,
41    /// as opposed to in a descendent widget.
42    ///
43    /// See also [`contains-pointer`][struct@crate::EventControllerMotion#contains-pointer].
44    ///
45    /// When handling crossing events, this property is updated
46    /// before [`enter`][struct@crate::EventControllerMotion#enter], but after
47    /// [`leave`][struct@crate::EventControllerMotion#leave] is emitted.
48    ///
49    /// Readable
50    /// <details><summary><h4>EventController</h4></summary>
51    ///
52    ///
53    /// #### `name`
54    ///  The name for this controller, typically used for debugging purposes.
55    ///
56    /// Readable | Writeable
57    ///
58    ///
59    /// #### `propagation-limit`
60    ///  The limit for which events this controller will handle.
61    ///
62    /// Readable | Writeable
63    ///
64    ///
65    /// #### `propagation-phase`
66    ///  The propagation phase at which this controller will handle events.
67    ///
68    /// Readable | Writeable
69    ///
70    ///
71    /// #### `widget`
72    ///  The widget receiving the `GdkEvents` that the controller will handle.
73    ///
74    /// Readable
75    /// </details>
76    ///
77    /// ## Signals
78    ///
79    ///
80    /// #### `enter`
81    ///  Signals that the pointer has entered the widget.
82    ///
83    ///
84    ///
85    ///
86    /// #### `leave`
87    ///  Signals that the pointer has left the widget.
88    ///
89    ///
90    ///
91    ///
92    /// #### `motion`
93    ///  Emitted when the pointer moves inside the widget.
94    ///
95    ///
96    ///
97    /// # Implements
98    ///
99    /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`], [`EventControllerExtManual`][trait@crate::prelude::EventControllerExtManual]
100    #[doc(alias = "GtkEventControllerMotion")]
101    pub struct EventControllerMotion(Object<ffi::GtkEventControllerMotion, ffi::GtkEventControllerMotionClass>) @extends EventController;
102
103    match fn {
104        type_ => || ffi::gtk_event_controller_motion_get_type(),
105    }
106}
107
108impl EventControllerMotion {
109    /// Creates a new event controller that will handle motion events.
110    ///
111    /// # Returns
112    ///
113    /// a new [`EventControllerMotion`][crate::EventControllerMotion]
114    #[doc(alias = "gtk_event_controller_motion_new")]
115    pub fn new() -> EventControllerMotion {
116        assert_initialized_main_thread!();
117        unsafe {
118            EventController::from_glib_full(ffi::gtk_event_controller_motion_new()).unsafe_cast()
119        }
120    }
121
122    // rustdoc-stripper-ignore-next
123    /// Creates a new builder-pattern struct instance to construct [`EventControllerMotion`] objects.
124    ///
125    /// This method returns an instance of [`EventControllerMotionBuilder`](crate::builders::EventControllerMotionBuilder) which can be used to create [`EventControllerMotion`] objects.
126    pub fn builder() -> EventControllerMotionBuilder {
127        EventControllerMotionBuilder::new()
128    }
129
130    /// Returns if a pointer is within @self or one of its children.
131    ///
132    /// # Returns
133    ///
134    /// [`true`] if a pointer is within @self or one of its children
135    #[doc(alias = "gtk_event_controller_motion_contains_pointer")]
136    #[doc(alias = "contains-pointer")]
137    pub fn contains_pointer(&self) -> bool {
138        unsafe {
139            from_glib(ffi::gtk_event_controller_motion_contains_pointer(
140                self.to_glib_none().0,
141            ))
142        }
143    }
144
145    /// Returns if a pointer is within @self, but not one of its children.
146    ///
147    /// # Returns
148    ///
149    /// [`true`] if a pointer is within @self but not one of its children
150    #[doc(alias = "gtk_event_controller_motion_is_pointer")]
151    #[doc(alias = "is-pointer")]
152    pub fn is_pointer(&self) -> bool {
153        unsafe {
154            from_glib(ffi::gtk_event_controller_motion_is_pointer(
155                self.to_glib_none().0,
156            ))
157        }
158    }
159
160    /// Signals that the pointer has entered the widget.
161    /// ## `x`
162    /// coordinates of pointer location
163    /// ## `y`
164    /// coordinates of pointer location
165    #[doc(alias = "enter")]
166    pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
167        unsafe extern "C" fn enter_trampoline<F: Fn(&EventControllerMotion, f64, f64) + 'static>(
168            this: *mut ffi::GtkEventControllerMotion,
169            x: std::ffi::c_double,
170            y: std::ffi::c_double,
171            f: glib::ffi::gpointer,
172        ) {
173            unsafe {
174                let f: &F = &*(f as *const F);
175                f(&from_glib_borrow(this), x, y)
176            }
177        }
178        unsafe {
179            let f: Box_<F> = Box_::new(f);
180            connect_raw(
181                self.as_ptr() as *mut _,
182                c"enter".as_ptr() as *const _,
183                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
184                    enter_trampoline::<F> as *const (),
185                )),
186                Box_::into_raw(f),
187            )
188        }
189    }
190
191    /// Signals that the pointer has left the widget.
192    #[doc(alias = "leave")]
193    pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
194        unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerMotion) + 'static>(
195            this: *mut ffi::GtkEventControllerMotion,
196            f: glib::ffi::gpointer,
197        ) {
198            unsafe {
199                let f: &F = &*(f as *const F);
200                f(&from_glib_borrow(this))
201            }
202        }
203        unsafe {
204            let f: Box_<F> = Box_::new(f);
205            connect_raw(
206                self.as_ptr() as *mut _,
207                c"leave".as_ptr() as *const _,
208                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
209                    leave_trampoline::<F> as *const (),
210                )),
211                Box_::into_raw(f),
212            )
213        }
214    }
215
216    /// Emitted when the pointer moves inside the widget.
217    /// ## `x`
218    /// the x coordinate
219    /// ## `y`
220    /// the y coordinate
221    #[doc(alias = "motion")]
222    pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
223        unsafe extern "C" fn motion_trampoline<
224            F: Fn(&EventControllerMotion, f64, f64) + 'static,
225        >(
226            this: *mut ffi::GtkEventControllerMotion,
227            x: std::ffi::c_double,
228            y: std::ffi::c_double,
229            f: glib::ffi::gpointer,
230        ) {
231            unsafe {
232                let f: &F = &*(f as *const F);
233                f(&from_glib_borrow(this), x, y)
234            }
235        }
236        unsafe {
237            let f: Box_<F> = Box_::new(f);
238            connect_raw(
239                self.as_ptr() as *mut _,
240                c"motion".as_ptr() as *const _,
241                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
242                    motion_trampoline::<F> as *const (),
243                )),
244                Box_::into_raw(f),
245            )
246        }
247    }
248
249    #[doc(alias = "contains-pointer")]
250    pub fn connect_contains_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
251        unsafe extern "C" fn notify_contains_pointer_trampoline<
252            F: Fn(&EventControllerMotion) + 'static,
253        >(
254            this: *mut ffi::GtkEventControllerMotion,
255            _param_spec: glib::ffi::gpointer,
256            f: glib::ffi::gpointer,
257        ) {
258            unsafe {
259                let f: &F = &*(f as *const F);
260                f(&from_glib_borrow(this))
261            }
262        }
263        unsafe {
264            let f: Box_<F> = Box_::new(f);
265            connect_raw(
266                self.as_ptr() as *mut _,
267                c"notify::contains-pointer".as_ptr() as *const _,
268                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
269                    notify_contains_pointer_trampoline::<F> as *const (),
270                )),
271                Box_::into_raw(f),
272            )
273        }
274    }
275
276    #[doc(alias = "is-pointer")]
277    pub fn connect_is_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
278        unsafe extern "C" fn notify_is_pointer_trampoline<
279            F: Fn(&EventControllerMotion) + 'static,
280        >(
281            this: *mut ffi::GtkEventControllerMotion,
282            _param_spec: glib::ffi::gpointer,
283            f: glib::ffi::gpointer,
284        ) {
285            unsafe {
286                let f: &F = &*(f as *const F);
287                f(&from_glib_borrow(this))
288            }
289        }
290        unsafe {
291            let f: Box_<F> = Box_::new(f);
292            connect_raw(
293                self.as_ptr() as *mut _,
294                c"notify::is-pointer".as_ptr() as *const _,
295                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
296                    notify_is_pointer_trampoline::<F> as *const (),
297                )),
298                Box_::into_raw(f),
299            )
300        }
301    }
302}
303
304impl Default for EventControllerMotion {
305    fn default() -> Self {
306        Self::new()
307    }
308}
309
310// rustdoc-stripper-ignore-next
311/// A [builder-pattern] type to construct [`EventControllerMotion`] objects.
312///
313/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
314#[must_use = "The builder must be built to be used"]
315pub struct EventControllerMotionBuilder {
316    builder: glib::object::ObjectBuilder<'static, EventControllerMotion>,
317}
318
319impl EventControllerMotionBuilder {
320    fn new() -> Self {
321        Self {
322            builder: glib::object::Object::builder(),
323        }
324    }
325
326    /// The name for this controller, typically used for debugging purposes.
327    pub fn name(self, name: impl Into<glib::GString>) -> Self {
328        Self {
329            builder: self.builder.property("name", name.into()),
330        }
331    }
332
333    /// The limit for which events this controller will handle.
334    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
335        Self {
336            builder: self
337                .builder
338                .property("propagation-limit", propagation_limit),
339        }
340    }
341
342    /// The propagation phase at which this controller will handle events.
343    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
344        Self {
345            builder: self
346                .builder
347                .property("propagation-phase", propagation_phase),
348        }
349    }
350
351    // rustdoc-stripper-ignore-next
352    /// Build the [`EventControllerMotion`].
353    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
354    pub fn build(self) -> EventControllerMotion {
355        assert_initialized_main_thread!();
356        self.builder.build()
357    }
358}