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, PropagationPhase, 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    // rustdoc-stripper-ignore-next
72    /// Creates a new builder-pattern struct instance to construct [`EventControllerMotion`] objects.
73    ///
74    /// This method returns an instance of [`EventControllerMotionBuilder`](crate::builders::EventControllerMotionBuilder) which can be used to create [`EventControllerMotion`] objects.
75    pub fn builder() -> EventControllerMotionBuilder {
76        EventControllerMotionBuilder::new()
77    }
78
79    /// Signals that the pointer has entered the widget.
80    /// ## `x`
81    /// the x coordinate
82    /// ## `y`
83    /// the y coordinate
84    #[doc(alias = "enter")]
85    pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
86        unsafe extern "C" fn enter_trampoline<F: Fn(&EventControllerMotion, f64, f64) + 'static>(
87            this: *mut ffi::GtkEventControllerMotion,
88            x: std::ffi::c_double,
89            y: std::ffi::c_double,
90            f: glib::ffi::gpointer,
91        ) {
92            unsafe {
93                let f: &F = &*(f as *const F);
94                f(&from_glib_borrow(this), x, y)
95            }
96        }
97        unsafe {
98            let f: Box_<F> = Box_::new(f);
99            connect_raw(
100                self.as_ptr() as *mut _,
101                c"enter".as_ptr(),
102                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
103                    enter_trampoline::<F> as *const (),
104                )),
105                Box_::into_raw(f),
106            )
107        }
108    }
109
110    /// Signals that pointer has left the widget.
111    #[doc(alias = "leave")]
112    pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
113        unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerMotion) + 'static>(
114            this: *mut ffi::GtkEventControllerMotion,
115            f: glib::ffi::gpointer,
116        ) {
117            unsafe {
118                let f: &F = &*(f as *const F);
119                f(&from_glib_borrow(this))
120            }
121        }
122        unsafe {
123            let f: Box_<F> = Box_::new(f);
124            connect_raw(
125                self.as_ptr() as *mut _,
126                c"leave".as_ptr(),
127                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
128                    leave_trampoline::<F> as *const (),
129                )),
130                Box_::into_raw(f),
131            )
132        }
133    }
134
135    /// Emitted when the pointer moves inside the widget.
136    /// ## `x`
137    /// the x coordinate
138    /// ## `y`
139    /// the y coordinate
140    #[doc(alias = "motion")]
141    pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
142        unsafe extern "C" fn motion_trampoline<
143            F: Fn(&EventControllerMotion, f64, f64) + 'static,
144        >(
145            this: *mut ffi::GtkEventControllerMotion,
146            x: std::ffi::c_double,
147            y: std::ffi::c_double,
148            f: glib::ffi::gpointer,
149        ) {
150            unsafe {
151                let f: &F = &*(f as *const F);
152                f(&from_glib_borrow(this), x, y)
153            }
154        }
155        unsafe {
156            let f: Box_<F> = Box_::new(f);
157            connect_raw(
158                self.as_ptr() as *mut _,
159                c"motion".as_ptr(),
160                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
161                    motion_trampoline::<F> as *const (),
162                )),
163                Box_::into_raw(f),
164            )
165        }
166    }
167}
168
169#[cfg(feature = "v3_24")]
170#[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
171impl Default for EventControllerMotion {
172    fn default() -> Self {
173        glib::object::Object::new::<Self>()
174    }
175}
176
177// rustdoc-stripper-ignore-next
178/// A [builder-pattern] type to construct [`EventControllerMotion`] objects.
179///
180/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
181#[must_use = "The builder must be built to be used"]
182pub struct EventControllerMotionBuilder {
183    builder: glib::object::ObjectBuilder<'static, EventControllerMotion>,
184}
185
186impl EventControllerMotionBuilder {
187    fn new() -> Self {
188        Self {
189            builder: glib::object::Object::builder(),
190        }
191    }
192
193    /// The propagation phase at which this controller will handle events.
194    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
195        Self {
196            builder: self
197                .builder
198                .property("propagation-phase", propagation_phase),
199        }
200    }
201
202    /// The widget receiving the `GdkEvents` that the controller will handle.
203    pub fn widget(self, widget: &impl IsA<Widget>) -> Self {
204        Self {
205            builder: self.builder.property("widget", widget.clone().upcast()),
206        }
207    }
208
209    // rustdoc-stripper-ignore-next
210    /// Build the [`EventControllerMotion`].
211    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
212    pub fn build(self) -> EventControllerMotion {
213        assert_initialized_main_thread!();
214        self.builder.build()
215    }
216}