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