Skip to main content

gtk/auto/
gesture_multi_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    /// [`GestureMultiPress`][crate::GestureMultiPress] is a [`Gesture`][crate::Gesture] implementation able to recognize
16    /// multiple clicks on a nearby zone, which can be listened for through the
17    /// [`pressed`][struct@crate::GestureMultiPress#pressed] signal. Whenever time or distance between
18    /// clicks exceed the GTK+ defaults, [`stopped`][struct@crate::GestureMultiPress#stopped] is emitted,
19    /// and the click counter is reset.
20    ///
21    /// Callers may also restrict the area that is considered valid for a >1
22    /// touch/button press through [`set_area()`][Self::set_area()], so any
23    /// click happening outside that area is considered to be a first click of
24    /// its own.
25    ///
26    /// ## Signals
27    ///
28    ///
29    /// #### `pressed`
30    ///  This signal is emitted whenever a button or touch press happens.
31    ///
32    ///
33    ///
34    ///
35    /// #### `released`
36    ///  This signal is emitted when a button or touch is released. `n_press`
37    /// will report the number of press that is paired to this event, note
38    /// that [`stopped`][struct@crate::GestureMultiPress#stopped] may have been emitted between the
39    /// press and its release, `n_press` will only start over at the next press.
40    ///
41    ///
42    ///
43    ///
44    /// #### `stopped`
45    ///  This signal is emitted whenever any time/distance threshold has
46    /// been exceeded.
47    ///
48    ///
49    /// <details><summary><h4>Gesture</h4></summary>
50    ///
51    ///
52    /// #### `begin`
53    ///  This signal is emitted when the gesture is recognized. This means the
54    /// number of touch sequences matches [`n-points`][struct@crate::Gesture#n-points], and the [`check`][struct@crate::Gesture#check]
55    /// handler(s) returned [`true`].
56    ///
57    /// Note: These conditions may also happen when an extra touch (eg. a third touch
58    /// on a 2-touches gesture) is lifted, in that situation `sequence` won't pertain
59    /// to the current set of active touches, so don't rely on this being true.
60    ///
61    ///
62    ///
63    ///
64    /// #### `cancel`
65    ///  This signal is emitted whenever a sequence is cancelled. This usually
66    /// happens on active touches when [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called
67    /// on `gesture` (manually, due to grabs...), or the individual `sequence`
68    /// was claimed by parent widgets' controllers (see [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
69    ///
70    /// `gesture` must forget everything about `sequence` as a reaction to this signal.
71    ///
72    ///
73    ///
74    ///
75    /// #### `end`
76    ///  This signal is emitted when `gesture` either stopped recognizing the event
77    /// sequences as something to be handled (the [`check`][struct@crate::Gesture#check] handler returned
78    /// [`false`]), or the number of touch sequences became higher or lower than
79    /// [`n-points`][struct@crate::Gesture#n-points].
80    ///
81    /// Note: `sequence` might not pertain to the group of sequences that were
82    /// previously triggering recognition on `gesture` (ie. a just pressed touch
83    /// sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]). This situation may be detected
84    /// by checking through [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
85    ///
86    ///
87    ///
88    ///
89    /// #### `sequence-state-changed`
90    ///  This signal is emitted whenever a sequence state changes. See
91    /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know more about the expectable
92    /// sequence lifetimes.
93    ///
94    ///
95    ///
96    ///
97    /// #### `update`
98    ///  This signal is emitted whenever an event is handled while the gesture is
99    /// recognized. `sequence` is guaranteed to pertain to the set of active touches.
100    ///
101    ///
102    /// </details>
103    ///
104    /// # Implements
105    ///
106    /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
107    #[doc(alias = "GtkGestureMultiPress")]
108    pub struct GestureMultiPress(Object<ffi::GtkGestureMultiPress, ffi::GtkGestureMultiPressClass>) @extends GestureSingle, Gesture, EventController;
109
110    match fn {
111        type_ => || ffi::gtk_gesture_multi_press_get_type(),
112    }
113}
114
115impl GestureMultiPress {
116    /// Returns a newly created [`Gesture`][crate::Gesture] that recognizes single and multiple
117    /// presses.
118    /// ## `widget`
119    /// a [`Widget`][crate::Widget]
120    ///
121    /// # Returns
122    ///
123    /// a newly created [`GestureMultiPress`][crate::GestureMultiPress]
124    #[doc(alias = "gtk_gesture_multi_press_new")]
125    pub fn new(widget: &impl IsA<Widget>) -> GestureMultiPress {
126        skip_assert_initialized!();
127        unsafe {
128            Gesture::from_glib_full(ffi::gtk_gesture_multi_press_new(
129                widget.as_ref().to_glib_none().0,
130            ))
131            .unsafe_cast()
132        }
133    }
134
135    // rustdoc-stripper-ignore-next
136    /// Creates a new builder-pattern struct instance to construct [`GestureMultiPress`] objects.
137    ///
138    /// This method returns an instance of [`GestureMultiPressBuilder`](crate::builders::GestureMultiPressBuilder) which can be used to create [`GestureMultiPress`] objects.
139    pub fn builder() -> GestureMultiPressBuilder {
140        GestureMultiPressBuilder::new()
141    }
142
143    /// If an area was set through [`set_area()`][Self::set_area()],
144    /// this function will return [`true`] and fill in `rect` with the
145    /// press area. See [`set_area()`][Self::set_area()] for more
146    /// details on what the press area represents.
147    ///
148    /// # Returns
149    ///
150    /// [`true`] if `rect` was filled with the press area
151    ///
152    /// ## `rect`
153    /// return location for the press area
154    #[doc(alias = "gtk_gesture_multi_press_get_area")]
155    #[doc(alias = "get_area")]
156    pub fn area(&self) -> Option<gdk::Rectangle> {
157        unsafe {
158            let mut rect = gdk::Rectangle::uninitialized();
159            let ret = from_glib(ffi::gtk_gesture_multi_press_get_area(
160                self.to_glib_none().0,
161                rect.to_glib_none_mut().0,
162            ));
163            if ret { Some(rect) } else { None }
164        }
165    }
166
167    /// If `rect` is non-[`None`], the press area will be checked to be
168    /// confined within the rectangle, otherwise the button count
169    /// will be reset so the press is seen as being the first one.
170    /// If `rect` is [`None`], the area will be reset to an unrestricted
171    /// state.
172    ///
173    /// Note: The rectangle is only used to determine whether any
174    /// non-first click falls within the expected area. This is not
175    /// akin to an input shape.
176    /// ## `rect`
177    /// rectangle to receive coordinates on
178    #[doc(alias = "gtk_gesture_multi_press_set_area")]
179    pub fn set_area(&self, rect: Option<&gdk::Rectangle>) {
180        unsafe {
181            ffi::gtk_gesture_multi_press_set_area(self.to_glib_none().0, rect.to_glib_none().0);
182        }
183    }
184
185    /// This signal is emitted whenever a button or touch press happens.
186    /// ## `n_press`
187    /// how many touch/button presses happened with this one
188    /// ## `x`
189    /// The X coordinate, in widget allocation coordinates
190    /// ## `y`
191    /// The Y coordinate, in widget allocation coordinates
192    #[doc(alias = "pressed")]
193    pub fn connect_pressed<F: Fn(&Self, i32, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
194        unsafe extern "C" fn pressed_trampoline<
195            F: Fn(&GestureMultiPress, i32, f64, f64) + 'static,
196        >(
197            this: *mut ffi::GtkGestureMultiPress,
198            n_press: std::ffi::c_int,
199            x: std::ffi::c_double,
200            y: std::ffi::c_double,
201            f: glib::ffi::gpointer,
202        ) {
203            unsafe {
204                let f: &F = &*(f as *const F);
205                f(&from_glib_borrow(this), n_press, x, y)
206            }
207        }
208        unsafe {
209            let f: Box_<F> = Box_::new(f);
210            connect_raw(
211                self.as_ptr() as *mut _,
212                c"pressed".as_ptr(),
213                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
214                    pressed_trampoline::<F> as *const (),
215                )),
216                Box_::into_raw(f),
217            )
218        }
219    }
220
221    /// This signal is emitted when a button or touch is released. `n_press`
222    /// will report the number of press that is paired to this event, note
223    /// that [`stopped`][struct@crate::GestureMultiPress#stopped] may have been emitted between the
224    /// press and its release, `n_press` will only start over at the next press.
225    /// ## `n_press`
226    /// number of press that is paired with this release
227    /// ## `x`
228    /// The X coordinate, in widget allocation coordinates
229    /// ## `y`
230    /// The Y coordinate, in widget allocation coordinates
231    #[doc(alias = "released")]
232    pub fn connect_released<F: Fn(&Self, i32, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
233        unsafe extern "C" fn released_trampoline<
234            F: Fn(&GestureMultiPress, i32, f64, f64) + 'static,
235        >(
236            this: *mut ffi::GtkGestureMultiPress,
237            n_press: std::ffi::c_int,
238            x: std::ffi::c_double,
239            y: std::ffi::c_double,
240            f: glib::ffi::gpointer,
241        ) {
242            unsafe {
243                let f: &F = &*(f as *const F);
244                f(&from_glib_borrow(this), n_press, x, y)
245            }
246        }
247        unsafe {
248            let f: Box_<F> = Box_::new(f);
249            connect_raw(
250                self.as_ptr() as *mut _,
251                c"released".as_ptr(),
252                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
253                    released_trampoline::<F> as *const (),
254                )),
255                Box_::into_raw(f),
256            )
257        }
258    }
259
260    /// This signal is emitted whenever any time/distance threshold has
261    /// been exceeded.
262    #[doc(alias = "stopped")]
263    pub fn connect_stopped<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
264        unsafe extern "C" fn stopped_trampoline<F: Fn(&GestureMultiPress) + 'static>(
265            this: *mut ffi::GtkGestureMultiPress,
266            f: glib::ffi::gpointer,
267        ) {
268            unsafe {
269                let f: &F = &*(f as *const F);
270                f(&from_glib_borrow(this))
271            }
272        }
273        unsafe {
274            let f: Box_<F> = Box_::new(f);
275            connect_raw(
276                self.as_ptr() as *mut _,
277                c"stopped".as_ptr(),
278                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
279                    stopped_trampoline::<F> as *const (),
280                )),
281                Box_::into_raw(f),
282            )
283        }
284    }
285}
286
287impl Default for GestureMultiPress {
288    fn default() -> Self {
289        glib::object::Object::new::<Self>()
290    }
291}
292
293// rustdoc-stripper-ignore-next
294/// A [builder-pattern] type to construct [`GestureMultiPress`] objects.
295///
296/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
297#[must_use = "The builder must be built to be used"]
298pub struct GestureMultiPressBuilder {
299    builder: glib::object::ObjectBuilder<'static, GestureMultiPress>,
300}
301
302impl GestureMultiPressBuilder {
303    fn new() -> Self {
304        Self {
305            builder: glib::object::Object::builder(),
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 [`GestureMultiPress`].
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) -> GestureMultiPress {
366        assert_initialized_main_thread!();
367        self.builder.build()
368    }
369}