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