Skip to main content

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