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