Skip to main content

gtk/auto/
gesture_single.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};
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    /// [`GestureSingle`][crate::GestureSingle] is a subclass of [`Gesture`][crate::Gesture], optimized (although
15    /// not restricted) for dealing with mouse and single-touch gestures. Under
16    /// interaction, these gestures stick to the first interacting sequence, which
17    /// is accessible through [`GestureSingleExt::current_sequence()`][crate::prelude::GestureSingleExt::current_sequence()] while the
18    /// gesture is being interacted with.
19    ///
20    /// By default gestures react to both `GDK_BUTTON_PRIMARY` and touch
21    /// events, [`GestureSingleExt::set_touch_only()`][crate::prelude::GestureSingleExt::set_touch_only()] can be used to change the
22    /// touch behavior. Callers may also specify a different mouse button number
23    /// to interact with through [`GestureSingleExt::set_button()`][crate::prelude::GestureSingleExt::set_button()], or react to any
24    /// mouse button by setting 0. While the gesture is active, the button being
25    /// currently pressed can be known through [`GestureSingleExt::current_button()`][crate::prelude::GestureSingleExt::current_button()].
26    ///
27    /// ## Properties
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><summary><h4>Gesture</h4></summary>
48    ///
49    ///
50    /// #### `n-points`
51    ///  The number of touch points that trigger recognition on this gesture,
52    ///
53    /// Readable | Writeable | Construct Only
54    ///
55    ///
56    /// #### `window`
57    ///  If non-[`None`], the gesture will only listen for events that happen on
58    /// this [`gdk::Window`][crate::gdk::Window], or a child of it.
59    ///
60    /// Readable | Writeable
61    /// </details>
62    /// <details><summary><h4>EventController</h4></summary>
63    ///
64    ///
65    /// #### `propagation-phase`
66    ///  The propagation phase at which this controller will handle events.
67    ///
68    /// Readable | Writeable
69    ///
70    ///
71    /// #### `widget`
72    ///  The widget receiving the `GdkEvents` that the controller will handle.
73    ///
74    /// Readable | Writeable | Construct Only
75    /// </details>
76    ///
77    /// # Implements
78    ///
79    /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
80    #[doc(alias = "GtkGestureSingle")]
81    pub struct GestureSingle(Object<ffi::GtkGestureSingle, ffi::GtkGestureSingleClass>) @extends Gesture, EventController;
82
83    match fn {
84        type_ => || ffi::gtk_gesture_single_get_type(),
85    }
86}
87
88impl GestureSingle {
89    pub const NONE: Option<&'static GestureSingle> = None;
90}
91
92mod sealed {
93    pub trait Sealed {}
94    impl<T: super::IsA<super::GestureSingle>> Sealed for T {}
95}
96
97/// Trait containing all [`struct@GestureSingle`] methods.
98///
99/// # Implementors
100///
101/// [`GestureDrag`][struct@crate::GestureDrag], [`GestureLongPress`][struct@crate::GestureLongPress], [`GestureMultiPress`][struct@crate::GestureMultiPress], [`GestureSingle`][struct@crate::GestureSingle], [`GestureStylus`][struct@crate::GestureStylus], [`GestureSwipe`][struct@crate::GestureSwipe]
102pub trait GestureSingleExt: IsA<GestureSingle> + sealed::Sealed + 'static {
103    /// Returns the button number `self` listens for, or 0 if `self`
104    /// reacts to any button press.
105    ///
106    /// # Returns
107    ///
108    /// The button number, or 0 for any button
109    #[doc(alias = "gtk_gesture_single_get_button")]
110    #[doc(alias = "get_button")]
111    fn button(&self) -> u32 {
112        unsafe { ffi::gtk_gesture_single_get_button(self.as_ref().to_glib_none().0) }
113    }
114
115    /// Returns the button number currently interacting with `self`, or 0 if there
116    /// is none.
117    ///
118    /// # Returns
119    ///
120    /// The current button number
121    #[doc(alias = "gtk_gesture_single_get_current_button")]
122    #[doc(alias = "get_current_button")]
123    fn current_button(&self) -> u32 {
124        unsafe { ffi::gtk_gesture_single_get_current_button(self.as_ref().to_glib_none().0) }
125    }
126
127    /// Returns the event sequence currently interacting with `self`.
128    /// This is only meaningful if [`GestureExt::is_active()`][crate::prelude::GestureExt::is_active()] returns [`true`].
129    ///
130    /// # Returns
131    ///
132    /// the current sequence
133    #[doc(alias = "gtk_gesture_single_get_current_sequence")]
134    #[doc(alias = "get_current_sequence")]
135    fn current_sequence(&self) -> Option<gdk::EventSequence> {
136        unsafe {
137            from_glib_full(ffi::gtk_gesture_single_get_current_sequence(
138                self.as_ref().to_glib_none().0,
139            ))
140        }
141    }
142
143    /// Gets whether a gesture is exclusive. For more information, see
144    /// [`set_exclusive()`][Self::set_exclusive()].
145    ///
146    /// # Returns
147    ///
148    /// Whether the gesture is exclusive
149    #[doc(alias = "gtk_gesture_single_get_exclusive")]
150    #[doc(alias = "get_exclusive")]
151    fn is_exclusive(&self) -> bool {
152        unsafe {
153            from_glib(ffi::gtk_gesture_single_get_exclusive(
154                self.as_ref().to_glib_none().0,
155            ))
156        }
157    }
158
159    /// Returns [`true`] if the gesture is only triggered by touch events.
160    ///
161    /// # Returns
162    ///
163    /// [`true`] if the gesture only handles touch events
164    #[doc(alias = "gtk_gesture_single_get_touch_only")]
165    #[doc(alias = "get_touch_only")]
166    fn is_touch_only(&self) -> bool {
167        unsafe {
168            from_glib(ffi::gtk_gesture_single_get_touch_only(
169                self.as_ref().to_glib_none().0,
170            ))
171        }
172    }
173
174    /// Sets the button number `self` listens to. If non-0, every
175    /// button press from a different button number will be ignored.
176    /// Touch events implicitly match with button 1.
177    /// ## `button`
178    /// button number to listen to, or 0 for any button
179    #[doc(alias = "gtk_gesture_single_set_button")]
180    fn set_button(&self, button: u32) {
181        unsafe {
182            ffi::gtk_gesture_single_set_button(self.as_ref().to_glib_none().0, button);
183        }
184    }
185
186    /// Sets whether `self` is exclusive. An exclusive gesture will
187    /// only handle pointer and "pointer emulated" touch events, so at
188    /// any given time, there is only one sequence able to interact with
189    /// those.
190    /// ## `exclusive`
191    /// [`true`] to make `self` exclusive
192    #[doc(alias = "gtk_gesture_single_set_exclusive")]
193    fn set_exclusive(&self, exclusive: bool) {
194        unsafe {
195            ffi::gtk_gesture_single_set_exclusive(
196                self.as_ref().to_glib_none().0,
197                exclusive.into_glib(),
198            );
199        }
200    }
201
202    /// If `touch_only` is [`true`], `self` will only handle events of type
203    /// `GDK_TOUCH_BEGIN`, `GDK_TOUCH_UPDATE` or `GDK_TOUCH_END`. If [`false`],
204    /// mouse events will be handled too.
205    /// ## `touch_only`
206    /// whether `self` handles only touch events
207    #[doc(alias = "gtk_gesture_single_set_touch_only")]
208    fn set_touch_only(&self, touch_only: bool) {
209        unsafe {
210            ffi::gtk_gesture_single_set_touch_only(
211                self.as_ref().to_glib_none().0,
212                touch_only.into_glib(),
213            );
214        }
215    }
216
217    #[doc(alias = "button")]
218    fn connect_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
219        unsafe extern "C" fn notify_button_trampoline<
220            P: IsA<GestureSingle>,
221            F: Fn(&P) + 'static,
222        >(
223            this: *mut ffi::GtkGestureSingle,
224            _param_spec: glib::ffi::gpointer,
225            f: glib::ffi::gpointer,
226        ) {
227            let f: &F = &*(f as *const F);
228            f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
229        }
230        unsafe {
231            let f: Box_<F> = Box_::new(f);
232            connect_raw(
233                self.as_ptr() as *mut _,
234                b"notify::button\0".as_ptr() as *const _,
235                Some(transmute::<_, unsafe extern "C" fn()>(
236                    notify_button_trampoline::<Self, F> as *const (),
237                )),
238                Box_::into_raw(f),
239            )
240        }
241    }
242
243    #[doc(alias = "exclusive")]
244    fn connect_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
245        unsafe extern "C" fn notify_exclusive_trampoline<
246            P: IsA<GestureSingle>,
247            F: Fn(&P) + 'static,
248        >(
249            this: *mut ffi::GtkGestureSingle,
250            _param_spec: glib::ffi::gpointer,
251            f: glib::ffi::gpointer,
252        ) {
253            let f: &F = &*(f as *const F);
254            f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
255        }
256        unsafe {
257            let f: Box_<F> = Box_::new(f);
258            connect_raw(
259                self.as_ptr() as *mut _,
260                b"notify::exclusive\0".as_ptr() as *const _,
261                Some(transmute::<_, unsafe extern "C" fn()>(
262                    notify_exclusive_trampoline::<Self, F> as *const (),
263                )),
264                Box_::into_raw(f),
265            )
266        }
267    }
268
269    #[doc(alias = "touch-only")]
270    fn connect_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
271        unsafe extern "C" fn notify_touch_only_trampoline<
272            P: IsA<GestureSingle>,
273            F: Fn(&P) + 'static,
274        >(
275            this: *mut ffi::GtkGestureSingle,
276            _param_spec: glib::ffi::gpointer,
277            f: glib::ffi::gpointer,
278        ) {
279            let f: &F = &*(f as *const F);
280            f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
281        }
282        unsafe {
283            let f: Box_<F> = Box_::new(f);
284            connect_raw(
285                self.as_ptr() as *mut _,
286                b"notify::touch-only\0".as_ptr() as *const _,
287                Some(transmute::<_, unsafe extern "C" fn()>(
288                    notify_touch_only_trampoline::<Self, F> as *const (),
289                )),
290                Box_::into_raw(f),
291            )
292        }
293    }
294}
295
296impl<O: IsA<GestureSingle>> GestureSingleExt for O {}
297
298impl fmt::Display for GestureSingle {
299    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
300        f.write_str("GestureSingle")
301    }
302}