Skip to main content

gtk4/auto/
gesture_click.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, 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    /// Recognizes click gestures.
16    ///
17    /// It is able to recognize multiple clicks on a nearby zone, which
18    /// can be listened for through the [`pressed`][struct@crate::GestureClick#pressed]
19    /// signal. Whenever time or distance between clicks exceed the GTK
20    /// defaults, [`stopped`][struct@crate::GestureClick#stopped] is emitted, and the
21    /// click counter is reset.
22    ///
23    /// ## Signals
24    ///
25    ///
26    /// #### `pressed`
27    ///  Emitted whenever a button or touch press happens.
28    ///
29    ///
30    ///
31    ///
32    /// #### `released`
33    ///  Emitted when a button or touch is released.
34    ///
35    /// @n_press will report the number of press that is paired to
36    /// this event, note that [`stopped`][struct@crate::GestureClick#stopped] may
37    /// have been emitted between the press and its release, @n_press
38    /// will only start over at the next press.
39    ///
40    ///
41    ///
42    ///
43    /// #### `stopped`
44    ///  Emitted whenever any time/distance threshold has been exceeded.
45    ///
46    ///
47    ///
48    ///
49    /// #### `unpaired-release`
50    ///  Emitted whenever the gesture receives a release
51    /// event that had no previous corresponding press.
52    ///
53    /// Due to implicit grabs, this can only happen on situations
54    /// where input is grabbed elsewhere mid-press or the pressed
55    /// widget voluntarily relinquishes its implicit grab.
56    ///
57    ///
58    /// <details><summary><h4>Gesture</h4></summary>
59    ///
60    ///
61    /// #### `begin`
62    ///  Emitted when the gesture is recognized.
63    ///
64    /// This means the number of touch sequences matches
65    /// [`n-points`][struct@crate::Gesture#n-points].
66    ///
67    /// Note: These conditions may also happen when an extra touch
68    /// (eg. a third touch on a 2-touches gesture) is lifted, in that
69    /// situation @sequence won't pertain to the current set of active
70    /// touches, so don't rely on this being true.
71    ///
72    ///
73    ///
74    ///
75    /// #### `cancel`
76    ///  Emitted whenever a sequence is cancelled.
77    ///
78    /// This usually happens on active touches when
79    /// [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called on @gesture
80    /// (manually, due to grabs...), or the individual @sequence
81    /// was claimed by parent widgets' controllers (see
82    /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
83    ///
84    /// @gesture must forget everything about @sequence as in
85    /// response to this signal.
86    ///
87    ///
88    ///
89    ///
90    /// #### `end`
91    ///  Emitted when @gesture either stopped recognizing the event
92    /// sequences as something to be handled, or the number of touch
93    /// sequences became higher or lower than [`n-points`][struct@crate::Gesture#n-points].
94    ///
95    /// Note: @sequence might not pertain to the group of sequences that
96    /// were previously triggering recognition on @gesture (ie. a just
97    /// pressed touch sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]).
98    /// This situation may be detected by checking through
99    /// [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
100    ///
101    ///
102    ///
103    ///
104    /// #### `sequence-state-changed`
105    ///  Emitted whenever a sequence state changes.
106    ///
107    /// See [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know
108    /// more about the expectable sequence lifetimes.
109    ///
110    ///
111    ///
112    ///
113    /// #### `update`
114    ///  Emitted whenever an event is handled while the gesture is recognized.
115    ///
116    /// @sequence is guaranteed to pertain to the set of active touches.
117    ///
118    ///
119    /// </details>
120    ///
121    /// # Implements
122    ///
123    /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`], [`EventControllerExtManual`][trait@crate::prelude::EventControllerExtManual]
124    #[doc(alias = "GtkGestureClick")]
125    pub struct GestureClick(Object<ffi::GtkGestureClick, ffi::GtkGestureClickClass>) @extends GestureSingle, Gesture, EventController;
126
127    match fn {
128        type_ => || ffi::gtk_gesture_click_get_type(),
129    }
130}
131
132impl GestureClick {
133    /// Returns a newly created [`Gesture`][crate::Gesture] that recognizes
134    /// single and multiple presses.
135    ///
136    /// # Returns
137    ///
138    /// a newly created [`GestureClick`][crate::GestureClick]
139    #[doc(alias = "gtk_gesture_click_new")]
140    pub fn new() -> GestureClick {
141        assert_initialized_main_thread!();
142        unsafe { Gesture::from_glib_full(ffi::gtk_gesture_click_new()).unsafe_cast() }
143    }
144
145    // rustdoc-stripper-ignore-next
146    /// Creates a new builder-pattern struct instance to construct [`GestureClick`] objects.
147    ///
148    /// This method returns an instance of [`GestureClickBuilder`](crate::builders::GestureClickBuilder) which can be used to create [`GestureClick`] objects.
149    pub fn builder() -> GestureClickBuilder {
150        GestureClickBuilder::new()
151    }
152
153    /// Emitted whenever a button or touch press happens.
154    /// ## `n_press`
155    /// how many touch/button presses happened with this one
156    /// ## `x`
157    /// The X coordinate, in widget allocation coordinates
158    /// ## `y`
159    /// The Y coordinate, in widget allocation coordinates
160    #[doc(alias = "pressed")]
161    pub fn connect_pressed<F: Fn(&Self, i32, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
162        unsafe extern "C" fn pressed_trampoline<F: Fn(&GestureClick, i32, f64, f64) + 'static>(
163            this: *mut ffi::GtkGestureClick,
164            n_press: std::ffi::c_int,
165            x: std::ffi::c_double,
166            y: std::ffi::c_double,
167            f: glib::ffi::gpointer,
168        ) {
169            unsafe {
170                let f: &F = &*(f as *const F);
171                f(&from_glib_borrow(this), n_press, x, y)
172            }
173        }
174        unsafe {
175            let f: Box_<F> = Box_::new(f);
176            connect_raw(
177                self.as_ptr() as *mut _,
178                c"pressed".as_ptr() as *const _,
179                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
180                    pressed_trampoline::<F> as *const (),
181                )),
182                Box_::into_raw(f),
183            )
184        }
185    }
186
187    /// Emitted when a button or touch is released.
188    ///
189    /// @n_press will report the number of press that is paired to
190    /// this event, note that [`stopped`][struct@crate::GestureClick#stopped] may
191    /// have been emitted between the press and its release, @n_press
192    /// will only start over at the next press.
193    /// ## `n_press`
194    /// number of press that is paired with this release
195    /// ## `x`
196    /// The X coordinate, in widget allocation coordinates
197    /// ## `y`
198    /// The Y coordinate, in widget allocation coordinates
199    #[doc(alias = "released")]
200    pub fn connect_released<F: Fn(&Self, i32, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
201        unsafe extern "C" fn released_trampoline<F: Fn(&GestureClick, i32, f64, f64) + 'static>(
202            this: *mut ffi::GtkGestureClick,
203            n_press: std::ffi::c_int,
204            x: std::ffi::c_double,
205            y: std::ffi::c_double,
206            f: glib::ffi::gpointer,
207        ) {
208            unsafe {
209                let f: &F = &*(f as *const F);
210                f(&from_glib_borrow(this), n_press, x, y)
211            }
212        }
213        unsafe {
214            let f: Box_<F> = Box_::new(f);
215            connect_raw(
216                self.as_ptr() as *mut _,
217                c"released".as_ptr() as *const _,
218                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
219                    released_trampoline::<F> as *const (),
220                )),
221                Box_::into_raw(f),
222            )
223        }
224    }
225
226    /// Emitted whenever any time/distance threshold has been exceeded.
227    #[doc(alias = "stopped")]
228    pub fn connect_stopped<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
229        unsafe extern "C" fn stopped_trampoline<F: Fn(&GestureClick) + 'static>(
230            this: *mut ffi::GtkGestureClick,
231            f: glib::ffi::gpointer,
232        ) {
233            unsafe {
234                let f: &F = &*(f as *const F);
235                f(&from_glib_borrow(this))
236            }
237        }
238        unsafe {
239            let f: Box_<F> = Box_::new(f);
240            connect_raw(
241                self.as_ptr() as *mut _,
242                c"stopped".as_ptr() as *const _,
243                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
244                    stopped_trampoline::<F> as *const (),
245                )),
246                Box_::into_raw(f),
247            )
248        }
249    }
250
251    /// Emitted whenever the gesture receives a release
252    /// event that had no previous corresponding press.
253    ///
254    /// Due to implicit grabs, this can only happen on situations
255    /// where input is grabbed elsewhere mid-press or the pressed
256    /// widget voluntarily relinquishes its implicit grab.
257    /// ## `x`
258    /// X coordinate of the event
259    /// ## `y`
260    /// Y coordinate of the event
261    /// ## `button`
262    /// Button being released
263    /// ## `sequence`
264    /// Sequence being released
265    #[doc(alias = "unpaired-release")]
266    pub fn connect_unpaired_release<
267        F: Fn(&Self, f64, f64, u32, Option<&gdk::EventSequence>) + 'static,
268    >(
269        &self,
270        f: F,
271    ) -> SignalHandlerId {
272        unsafe extern "C" fn unpaired_release_trampoline<
273            F: Fn(&GestureClick, f64, f64, u32, Option<&gdk::EventSequence>) + 'static,
274        >(
275            this: *mut ffi::GtkGestureClick,
276            x: std::ffi::c_double,
277            y: std::ffi::c_double,
278            button: std::ffi::c_uint,
279            sequence: *mut gdk::ffi::GdkEventSequence,
280            f: glib::ffi::gpointer,
281        ) {
282            unsafe {
283                let f: &F = &*(f as *const F);
284                f(
285                    &from_glib_borrow(this),
286                    x,
287                    y,
288                    button,
289                    Option::<gdk::EventSequence>::from_glib_borrow(sequence)
290                        .as_ref()
291                        .as_ref(),
292                )
293            }
294        }
295        unsafe {
296            let f: Box_<F> = Box_::new(f);
297            connect_raw(
298                self.as_ptr() as *mut _,
299                c"unpaired-release".as_ptr() as *const _,
300                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
301                    unpaired_release_trampoline::<F> as *const (),
302                )),
303                Box_::into_raw(f),
304            )
305        }
306    }
307}
308
309impl Default for GestureClick {
310    fn default() -> Self {
311        Self::new()
312    }
313}
314
315// rustdoc-stripper-ignore-next
316/// A [builder-pattern] type to construct [`GestureClick`] objects.
317///
318/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
319#[must_use = "The builder must be built to be used"]
320pub struct GestureClickBuilder {
321    builder: glib::object::ObjectBuilder<'static, GestureClick>,
322}
323
324impl GestureClickBuilder {
325    fn new() -> Self {
326        Self {
327            builder: glib::object::Object::builder(),
328        }
329    }
330
331    /// Mouse button number to listen to, or 0 to listen for any button.
332    pub fn button(self, button: u32) -> Self {
333        Self {
334            builder: self.builder.property("button", button),
335        }
336    }
337
338    /// Whether the gesture is exclusive.
339    ///
340    /// Exclusive gestures only listen to pointer and pointer emulated events.
341    pub fn exclusive(self, exclusive: bool) -> Self {
342        Self {
343            builder: self.builder.property("exclusive", exclusive),
344        }
345    }
346
347    /// Whether the gesture handles only touch events.
348    pub fn touch_only(self, touch_only: bool) -> Self {
349        Self {
350            builder: self.builder.property("touch-only", touch_only),
351        }
352    }
353
354    /// The number of touch points that trigger
355    /// recognition on this gesture.
356    pub fn n_points(self, n_points: u32) -> Self {
357        Self {
358            builder: self.builder.property("n-points", n_points),
359        }
360    }
361
362    /// The name for this controller, typically used for debugging purposes.
363    pub fn name(self, name: impl Into<glib::GString>) -> Self {
364        Self {
365            builder: self.builder.property("name", name.into()),
366        }
367    }
368
369    /// The limit for which events this controller will handle.
370    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
371        Self {
372            builder: self
373                .builder
374                .property("propagation-limit", propagation_limit),
375        }
376    }
377
378    /// The propagation phase at which this controller will handle events.
379    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
380        Self {
381            builder: self
382                .builder
383                .property("propagation-phase", propagation_phase),
384        }
385    }
386
387    // rustdoc-stripper-ignore-next
388    /// Build the [`GestureClick`].
389    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
390    pub fn build(self) -> GestureClick {
391        assert_initialized_main_thread!();
392        self.builder.build()
393    }
394}