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::{ffi, EventController, Gesture, GestureSingle, 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    /// [`GestureClick`][crate::GestureClick] is a [`Gesture`][crate::Gesture] implementation for clicks.
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`]
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            let f: &F = &*(f as *const F);
170            f(&from_glib_borrow(this), n_press, x, y)
171        }
172        unsafe {
173            let f: Box_<F> = Box_::new(f);
174            connect_raw(
175                self.as_ptr() as *mut _,
176                b"pressed\0".as_ptr() as *const _,
177                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
178                    pressed_trampoline::<F> as *const (),
179                )),
180                Box_::into_raw(f),
181            )
182        }
183    }
184
185    /// Emitted when a button or touch is released.
186    ///
187    /// @n_press will report the number of press that is paired to
188    /// this event, note that [`stopped`][struct@crate::GestureClick#stopped] may
189    /// have been emitted between the press and its release, @n_press
190    /// will only start over at the next press.
191    /// ## `n_press`
192    /// number of press that is paired with this release
193    /// ## `x`
194    /// The X coordinate, in widget allocation coordinates
195    /// ## `y`
196    /// The Y coordinate, in widget allocation coordinates
197    #[doc(alias = "released")]
198    pub fn connect_released<F: Fn(&Self, i32, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
199        unsafe extern "C" fn released_trampoline<F: Fn(&GestureClick, i32, f64, f64) + 'static>(
200            this: *mut ffi::GtkGestureClick,
201            n_press: std::ffi::c_int,
202            x: std::ffi::c_double,
203            y: std::ffi::c_double,
204            f: glib::ffi::gpointer,
205        ) {
206            let f: &F = &*(f as *const F);
207            f(&from_glib_borrow(this), n_press, x, y)
208        }
209        unsafe {
210            let f: Box_<F> = Box_::new(f);
211            connect_raw(
212                self.as_ptr() as *mut _,
213                b"released\0".as_ptr() as *const _,
214                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
215                    released_trampoline::<F> as *const (),
216                )),
217                Box_::into_raw(f),
218            )
219        }
220    }
221
222    /// Emitted whenever any time/distance threshold has been exceeded.
223    #[doc(alias = "stopped")]
224    pub fn connect_stopped<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
225        unsafe extern "C" fn stopped_trampoline<F: Fn(&GestureClick) + 'static>(
226            this: *mut ffi::GtkGestureClick,
227            f: glib::ffi::gpointer,
228        ) {
229            let f: &F = &*(f as *const F);
230            f(&from_glib_borrow(this))
231        }
232        unsafe {
233            let f: Box_<F> = Box_::new(f);
234            connect_raw(
235                self.as_ptr() as *mut _,
236                b"stopped\0".as_ptr() as *const _,
237                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
238                    stopped_trampoline::<F> as *const (),
239                )),
240                Box_::into_raw(f),
241            )
242        }
243    }
244
245    /// Emitted whenever the gesture receives a release
246    /// event that had no previous corresponding press.
247    ///
248    /// Due to implicit grabs, this can only happen on situations
249    /// where input is grabbed elsewhere mid-press or the pressed
250    /// widget voluntarily relinquishes its implicit grab.
251    /// ## `x`
252    /// X coordinate of the event
253    /// ## `y`
254    /// Y coordinate of the event
255    /// ## `button`
256    /// Button being released
257    /// ## `sequence`
258    /// Sequence being released
259    #[doc(alias = "unpaired-release")]
260    pub fn connect_unpaired_release<
261        F: Fn(&Self, f64, f64, u32, Option<&gdk::EventSequence>) + 'static,
262    >(
263        &self,
264        f: F,
265    ) -> SignalHandlerId {
266        unsafe extern "C" fn unpaired_release_trampoline<
267            F: Fn(&GestureClick, f64, f64, u32, Option<&gdk::EventSequence>) + 'static,
268        >(
269            this: *mut ffi::GtkGestureClick,
270            x: std::ffi::c_double,
271            y: std::ffi::c_double,
272            button: std::ffi::c_uint,
273            sequence: *mut gdk::ffi::GdkEventSequence,
274            f: glib::ffi::gpointer,
275        ) {
276            let f: &F = &*(f as *const F);
277            f(
278                &from_glib_borrow(this),
279                x,
280                y,
281                button,
282                Option::<gdk::EventSequence>::from_glib_borrow(sequence)
283                    .as_ref()
284                    .as_ref(),
285            )
286        }
287        unsafe {
288            let f: Box_<F> = Box_::new(f);
289            connect_raw(
290                self.as_ptr() as *mut _,
291                b"unpaired-release\0".as_ptr() as *const _,
292                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
293                    unpaired_release_trampoline::<F> as *const (),
294                )),
295                Box_::into_raw(f),
296            )
297        }
298    }
299}
300
301impl Default for GestureClick {
302    fn default() -> Self {
303        Self::new()
304    }
305}
306
307// rustdoc-stripper-ignore-next
308/// A [builder-pattern] type to construct [`GestureClick`] objects.
309///
310/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
311#[must_use = "The builder must be built to be used"]
312pub struct GestureClickBuilder {
313    builder: glib::object::ObjectBuilder<'static, GestureClick>,
314}
315
316impl GestureClickBuilder {
317    fn new() -> Self {
318        Self {
319            builder: glib::object::Object::builder(),
320        }
321    }
322
323    /// Mouse button number to listen to, or 0 to listen for any button.
324    pub fn button(self, button: u32) -> Self {
325        Self {
326            builder: self.builder.property("button", button),
327        }
328    }
329
330    /// Whether the gesture is exclusive.
331    ///
332    /// Exclusive gestures only listen to pointer and pointer emulated events.
333    pub fn exclusive(self, exclusive: bool) -> Self {
334        Self {
335            builder: self.builder.property("exclusive", exclusive),
336        }
337    }
338
339    /// Whether the gesture handles only touch events.
340    pub fn touch_only(self, touch_only: bool) -> Self {
341        Self {
342            builder: self.builder.property("touch-only", touch_only),
343        }
344    }
345
346    /// The number of touch points that trigger
347    /// recognition on this gesture.
348    pub fn n_points(self, n_points: u32) -> Self {
349        Self {
350            builder: self.builder.property("n-points", n_points),
351        }
352    }
353
354    /// The name for this controller, typically used for debugging purposes.
355    pub fn name(self, name: impl Into<glib::GString>) -> Self {
356        Self {
357            builder: self.builder.property("name", name.into()),
358        }
359    }
360
361    /// The limit for which events this controller will handle.
362    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
363        Self {
364            builder: self
365                .builder
366                .property("propagation-limit", propagation_limit),
367        }
368    }
369
370    /// The propagation phase at which this controller will handle events.
371    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
372        Self {
373            builder: self
374                .builder
375                .property("propagation-phase", propagation_phase),
376        }
377    }
378
379    // rustdoc-stripper-ignore-next
380    /// Build the [`GestureClick`].
381    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
382    pub fn build(self) -> GestureClick {
383        assert_initialized_main_thread!();
384        self.builder.build()
385    }
386}