gtk/auto/gesture_drag.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, Gesture, GestureSingle, PropagationPhase, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem, mem::transmute};
12
13glib::wrapper! {
14 /// [`GestureDrag`][crate::GestureDrag] is a [`Gesture`][crate::Gesture] implementation that recognizes drag
15 /// operations. The drag operation itself can be tracked throught the
16 /// [`drag-begin`][struct@crate::GestureDrag#drag-begin], [`drag-update`][struct@crate::GestureDrag#drag-update] and
17 /// [`drag-end`][struct@crate::GestureDrag#drag-end] signals, or the relevant coordinates be
18 /// extracted through [`GestureDragExt::offset()`][crate::prelude::GestureDragExt::offset()] and
19 /// [`GestureDragExt::start_point()`][crate::prelude::GestureDragExt::start_point()].
20 ///
21 /// ## Signals
22 ///
23 ///
24 /// #### `drag-begin`
25 /// This signal is emitted whenever dragging starts.
26 ///
27 ///
28 ///
29 ///
30 /// #### `drag-end`
31 /// This signal is emitted whenever the dragging is finished.
32 ///
33 ///
34 ///
35 ///
36 /// #### `drag-update`
37 /// This signal is emitted whenever the dragging point moves.
38 ///
39 ///
40 /// <details><summary><h4>Gesture</h4></summary>
41 ///
42 ///
43 /// #### `begin`
44 /// This signal is emitted when the gesture is recognized. This means the
45 /// number of touch sequences matches [`n-points`][struct@crate::Gesture#n-points], and the [`check`][struct@crate::Gesture#check]
46 /// handler(s) returned [`true`].
47 ///
48 /// Note: These conditions may also happen when an extra touch (eg. a third touch
49 /// on a 2-touches gesture) is lifted, in that situation `sequence` won't pertain
50 /// to the current set of active touches, so don't rely on this being true.
51 ///
52 ///
53 ///
54 ///
55 /// #### `cancel`
56 /// This signal is emitted whenever a sequence is cancelled. This usually
57 /// happens on active touches when [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called
58 /// on `gesture` (manually, due to grabs...), or the individual `sequence`
59 /// was claimed by parent widgets' controllers (see [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
60 ///
61 /// `gesture` must forget everything about `sequence` as a reaction to this signal.
62 ///
63 ///
64 ///
65 ///
66 /// #### `end`
67 /// This signal is emitted when `gesture` either stopped recognizing the event
68 /// sequences as something to be handled (the [`check`][struct@crate::Gesture#check] handler returned
69 /// [`false`]), or the number of touch sequences became higher or lower than
70 /// [`n-points`][struct@crate::Gesture#n-points].
71 ///
72 /// Note: `sequence` might not pertain to the group of sequences that were
73 /// previously triggering recognition on `gesture` (ie. a just pressed touch
74 /// sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]). This situation may be detected
75 /// by checking through [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
76 ///
77 ///
78 ///
79 ///
80 /// #### `sequence-state-changed`
81 /// This signal is emitted whenever a sequence state changes. See
82 /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know more about the expectable
83 /// sequence lifetimes.
84 ///
85 ///
86 ///
87 ///
88 /// #### `update`
89 /// This signal is emitted whenever an event is handled while the gesture is
90 /// recognized. `sequence` is guaranteed to pertain to the set of active touches.
91 ///
92 ///
93 /// </details>
94 ///
95 /// # Implements
96 ///
97 /// [`GestureDragExt`][trait@crate::prelude::GestureDragExt], [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
98 #[doc(alias = "GtkGestureDrag")]
99 pub struct GestureDrag(Object<ffi::GtkGestureDrag, ffi::GtkGestureDragClass>) @extends GestureSingle, Gesture, EventController;
100
101 match fn {
102 type_ => || ffi::gtk_gesture_drag_get_type(),
103 }
104}
105
106impl GestureDrag {
107 pub const NONE: Option<&'static GestureDrag> = None;
108
109 /// Returns a newly created [`Gesture`][crate::Gesture] that recognizes drags.
110 /// ## `widget`
111 /// a [`Widget`][crate::Widget]
112 ///
113 /// # Returns
114 ///
115 /// a newly created [`GestureDrag`][crate::GestureDrag]
116 #[doc(alias = "gtk_gesture_drag_new")]
117 pub fn new(widget: &impl IsA<Widget>) -> GestureDrag {
118 skip_assert_initialized!();
119 unsafe {
120 Gesture::from_glib_full(ffi::gtk_gesture_drag_new(widget.as_ref().to_glib_none().0))
121 .unsafe_cast()
122 }
123 }
124
125 // rustdoc-stripper-ignore-next
126 /// Creates a new builder-pattern struct instance to construct [`GestureDrag`] objects.
127 ///
128 /// This method returns an instance of [`GestureDragBuilder`](crate::builders::GestureDragBuilder) which can be used to create [`GestureDrag`] objects.
129 pub fn builder() -> GestureDragBuilder {
130 GestureDragBuilder::new()
131 }
132}
133
134impl Default for GestureDrag {
135 fn default() -> Self {
136 glib::object::Object::new::<Self>()
137 }
138}
139
140// rustdoc-stripper-ignore-next
141/// A [builder-pattern] type to construct [`GestureDrag`] objects.
142///
143/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
144#[must_use = "The builder must be built to be used"]
145pub struct GestureDragBuilder {
146 builder: glib::object::ObjectBuilder<'static, GestureDrag>,
147}
148
149impl GestureDragBuilder {
150 fn new() -> Self {
151 Self {
152 builder: glib::object::Object::builder(),
153 }
154 }
155
156 /// Mouse button number to listen to, or 0 to listen for any button.
157 pub fn button(self, button: u32) -> Self {
158 Self {
159 builder: self.builder.property("button", button),
160 }
161 }
162
163 /// Whether the gesture is exclusive. Exclusive gestures only listen to pointer
164 /// and pointer emulated events.
165 pub fn exclusive(self, exclusive: bool) -> Self {
166 Self {
167 builder: self.builder.property("exclusive", exclusive),
168 }
169 }
170
171 /// Whether the gesture handles only touch events.
172 pub fn touch_only(self, touch_only: bool) -> Self {
173 Self {
174 builder: self.builder.property("touch-only", touch_only),
175 }
176 }
177
178 /// The number of touch points that trigger recognition on this gesture,
179 pub fn n_points(self, n_points: u32) -> Self {
180 Self {
181 builder: self.builder.property("n-points", n_points),
182 }
183 }
184
185 /// If non-[`None`], the gesture will only listen for events that happen on
186 /// this [`gdk::Window`][crate::gdk::Window], or a child of it.
187 pub fn window(self, window: &gdk::Window) -> Self {
188 Self {
189 builder: self.builder.property("window", window.clone()),
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 [`GestureDrag`].
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) -> GestureDrag {
213 self.builder.build()
214 }
215}
216
217mod sealed {
218 pub trait Sealed {}
219 impl<T: super::IsA<super::GestureDrag>> Sealed for T {}
220}
221
222/// Trait containing all [`struct@GestureDrag`] methods.
223///
224/// # Implementors
225///
226/// [`GestureDrag`][struct@crate::GestureDrag], [`GesturePan`][struct@crate::GesturePan]
227pub trait GestureDragExt: IsA<GestureDrag> + sealed::Sealed + 'static {
228 /// If the `self` is active, this function returns [`true`] and
229 /// fills in `x` and `y` with the coordinates of the current point,
230 /// as an offset to the starting drag point.
231 ///
232 /// # Returns
233 ///
234 /// [`true`] if the gesture is active
235 ///
236 /// ## `x`
237 /// X offset for the current point
238 ///
239 /// ## `y`
240 /// Y offset for the current point
241 #[doc(alias = "gtk_gesture_drag_get_offset")]
242 #[doc(alias = "get_offset")]
243 fn offset(&self) -> Option<(f64, f64)> {
244 unsafe {
245 let mut x = mem::MaybeUninit::uninit();
246 let mut y = mem::MaybeUninit::uninit();
247 let ret = from_glib(ffi::gtk_gesture_drag_get_offset(
248 self.as_ref().to_glib_none().0,
249 x.as_mut_ptr(),
250 y.as_mut_ptr(),
251 ));
252 if ret {
253 Some((x.assume_init(), y.assume_init()))
254 } else {
255 None
256 }
257 }
258 }
259
260 /// If the `self` is active, this function returns [`true`]
261 /// and fills in `x` and `y` with the drag start coordinates,
262 /// in window-relative coordinates.
263 ///
264 /// # Returns
265 ///
266 /// [`true`] if the gesture is active
267 ///
268 /// ## `x`
269 /// X coordinate for the drag start point
270 ///
271 /// ## `y`
272 /// Y coordinate for the drag start point
273 #[doc(alias = "gtk_gesture_drag_get_start_point")]
274 #[doc(alias = "get_start_point")]
275 fn start_point(&self) -> Option<(f64, f64)> {
276 unsafe {
277 let mut x = mem::MaybeUninit::uninit();
278 let mut y = mem::MaybeUninit::uninit();
279 let ret = from_glib(ffi::gtk_gesture_drag_get_start_point(
280 self.as_ref().to_glib_none().0,
281 x.as_mut_ptr(),
282 y.as_mut_ptr(),
283 ));
284 if ret {
285 Some((x.assume_init(), y.assume_init()))
286 } else {
287 None
288 }
289 }
290 }
291
292 /// This signal is emitted whenever dragging starts.
293 /// ## `start_x`
294 /// X coordinate, relative to the widget allocation
295 /// ## `start_y`
296 /// Y coordinate, relative to the widget allocation
297 #[doc(alias = "drag-begin")]
298 fn connect_drag_begin<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
299 unsafe extern "C" fn drag_begin_trampoline<
300 P: IsA<GestureDrag>,
301 F: Fn(&P, f64, f64) + 'static,
302 >(
303 this: *mut ffi::GtkGestureDrag,
304 start_x: libc::c_double,
305 start_y: libc::c_double,
306 f: glib::ffi::gpointer,
307 ) {
308 let f: &F = &*(f as *const F);
309 f(
310 GestureDrag::from_glib_borrow(this).unsafe_cast_ref(),
311 start_x,
312 start_y,
313 )
314 }
315 unsafe {
316 let f: Box_<F> = Box_::new(f);
317 connect_raw(
318 self.as_ptr() as *mut _,
319 b"drag-begin\0".as_ptr() as *const _,
320 Some(transmute::<_, unsafe extern "C" fn()>(
321 drag_begin_trampoline::<Self, F> as *const (),
322 )),
323 Box_::into_raw(f),
324 )
325 }
326 }
327
328 /// This signal is emitted whenever the dragging is finished.
329 /// ## `offset_x`
330 /// X offset, relative to the start point
331 /// ## `offset_y`
332 /// Y offset, relative to the start point
333 #[doc(alias = "drag-end")]
334 fn connect_drag_end<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
335 unsafe extern "C" fn drag_end_trampoline<
336 P: IsA<GestureDrag>,
337 F: Fn(&P, f64, f64) + 'static,
338 >(
339 this: *mut ffi::GtkGestureDrag,
340 offset_x: libc::c_double,
341 offset_y: libc::c_double,
342 f: glib::ffi::gpointer,
343 ) {
344 let f: &F = &*(f as *const F);
345 f(
346 GestureDrag::from_glib_borrow(this).unsafe_cast_ref(),
347 offset_x,
348 offset_y,
349 )
350 }
351 unsafe {
352 let f: Box_<F> = Box_::new(f);
353 connect_raw(
354 self.as_ptr() as *mut _,
355 b"drag-end\0".as_ptr() as *const _,
356 Some(transmute::<_, unsafe extern "C" fn()>(
357 drag_end_trampoline::<Self, F> as *const (),
358 )),
359 Box_::into_raw(f),
360 )
361 }
362 }
363
364 /// This signal is emitted whenever the dragging point moves.
365 /// ## `offset_x`
366 /// X offset, relative to the start point
367 /// ## `offset_y`
368 /// Y offset, relative to the start point
369 #[doc(alias = "drag-update")]
370 fn connect_drag_update<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
371 unsafe extern "C" fn drag_update_trampoline<
372 P: IsA<GestureDrag>,
373 F: Fn(&P, f64, f64) + 'static,
374 >(
375 this: *mut ffi::GtkGestureDrag,
376 offset_x: libc::c_double,
377 offset_y: libc::c_double,
378 f: glib::ffi::gpointer,
379 ) {
380 let f: &F = &*(f as *const F);
381 f(
382 GestureDrag::from_glib_borrow(this).unsafe_cast_ref(),
383 offset_x,
384 offset_y,
385 )
386 }
387 unsafe {
388 let f: Box_<F> = Box_::new(f);
389 connect_raw(
390 self.as_ptr() as *mut _,
391 b"drag-update\0".as_ptr() as *const _,
392 Some(transmute::<_, unsafe extern "C" fn()>(
393 drag_update_trampoline::<Self, F> as *const (),
394 )),
395 Box_::into_raw(f),
396 )
397 }
398 }
399}
400
401impl<O: IsA<GestureDrag>> GestureDragExt for O {}
402
403impl fmt::Display for GestureDrag {
404 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
405 f.write_str("GestureDrag")
406 }
407}