Skip to main content

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