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 /// 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`]
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 let f: &F = &*(f as *const F);
174 f(&from_glib_borrow(this), x, y)
175 }
176 unsafe {
177 let f: Box_<F> = Box_::new(f);
178 connect_raw(
179 self.as_ptr() as *mut _,
180 c"enter".as_ptr() as *const _,
181 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
182 enter_trampoline::<F> as *const (),
183 )),
184 Box_::into_raw(f),
185 )
186 }
187 }
188
189 /// Signals that the pointer has left the widget.
190 #[doc(alias = "leave")]
191 pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
192 unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerMotion) + 'static>(
193 this: *mut ffi::GtkEventControllerMotion,
194 f: glib::ffi::gpointer,
195 ) {
196 let f: &F = &*(f as *const F);
197 f(&from_glib_borrow(this))
198 }
199 unsafe {
200 let f: Box_<F> = Box_::new(f);
201 connect_raw(
202 self.as_ptr() as *mut _,
203 c"leave".as_ptr() as *const _,
204 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
205 leave_trampoline::<F> as *const (),
206 )),
207 Box_::into_raw(f),
208 )
209 }
210 }
211
212 /// Emitted when the pointer moves inside the widget.
213 /// ## `x`
214 /// the x coordinate
215 /// ## `y`
216 /// the y coordinate
217 #[doc(alias = "motion")]
218 pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
219 unsafe extern "C" fn motion_trampoline<
220 F: Fn(&EventControllerMotion, f64, f64) + 'static,
221 >(
222 this: *mut ffi::GtkEventControllerMotion,
223 x: std::ffi::c_double,
224 y: std::ffi::c_double,
225 f: glib::ffi::gpointer,
226 ) {
227 let f: &F = &*(f as *const F);
228 f(&from_glib_borrow(this), x, y)
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"motion".as_ptr() as *const _,
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 motion_trampoline::<F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242
243 #[doc(alias = "contains-pointer")]
244 pub fn connect_contains_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
245 unsafe extern "C" fn notify_contains_pointer_trampoline<
246 F: Fn(&EventControllerMotion) + 'static,
247 >(
248 this: *mut ffi::GtkEventControllerMotion,
249 _param_spec: glib::ffi::gpointer,
250 f: glib::ffi::gpointer,
251 ) {
252 let f: &F = &*(f as *const F);
253 f(&from_glib_borrow(this))
254 }
255 unsafe {
256 let f: Box_<F> = Box_::new(f);
257 connect_raw(
258 self.as_ptr() as *mut _,
259 c"notify::contains-pointer".as_ptr() as *const _,
260 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261 notify_contains_pointer_trampoline::<F> as *const (),
262 )),
263 Box_::into_raw(f),
264 )
265 }
266 }
267
268 #[doc(alias = "is-pointer")]
269 pub fn connect_is_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
270 unsafe extern "C" fn notify_is_pointer_trampoline<
271 F: Fn(&EventControllerMotion) + 'static,
272 >(
273 this: *mut ffi::GtkEventControllerMotion,
274 _param_spec: glib::ffi::gpointer,
275 f: glib::ffi::gpointer,
276 ) {
277 let f: &F = &*(f as *const F);
278 f(&from_glib_borrow(this))
279 }
280 unsafe {
281 let f: Box_<F> = Box_::new(f);
282 connect_raw(
283 self.as_ptr() as *mut _,
284 c"notify::is-pointer".as_ptr() as *const _,
285 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
286 notify_is_pointer_trampoline::<F> as *const (),
287 )),
288 Box_::into_raw(f),
289 )
290 }
291 }
292}
293
294impl Default for EventControllerMotion {
295 fn default() -> Self {
296 Self::new()
297 }
298}
299
300// rustdoc-stripper-ignore-next
301/// A [builder-pattern] type to construct [`EventControllerMotion`] objects.
302///
303/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
304#[must_use = "The builder must be built to be used"]
305pub struct EventControllerMotionBuilder {
306 builder: glib::object::ObjectBuilder<'static, EventControllerMotion>,
307}
308
309impl EventControllerMotionBuilder {
310 fn new() -> Self {
311 Self {
312 builder: glib::object::Object::builder(),
313 }
314 }
315
316 /// The name for this controller, typically used for debugging purposes.
317 pub fn name(self, name: impl Into<glib::GString>) -> Self {
318 Self {
319 builder: self.builder.property("name", name.into()),
320 }
321 }
322
323 /// The limit for which events this controller will handle.
324 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
325 Self {
326 builder: self
327 .builder
328 .property("propagation-limit", propagation_limit),
329 }
330 }
331
332 /// The propagation phase at which this controller will handle events.
333 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
334 Self {
335 builder: self
336 .builder
337 .property("propagation-phase", propagation_phase),
338 }
339 }
340
341 // rustdoc-stripper-ignore-next
342 /// Build the [`EventControllerMotion`].
343 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
344 pub fn build(self) -> EventControllerMotion {
345 assert_initialized_main_thread!();
346 self.builder.build()
347 }
348}