Skip to main content

gtk/auto/
gesture_stylus.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    /// [`GestureStylus`][crate::GestureStylus] is a [`Gesture`][crate::Gesture] implementation specific to stylus
16    /// input. The provided signals just provide the basic information
17    ///
18    /// ## Signals
19    ///
20    ///
21    /// #### `down`
22    ///
23    ///
24    ///
25    /// #### `motion`
26    ///
27    ///
28    ///
29    /// #### `proximity`
30    ///
31    ///
32    ///
33    /// #### `up`
34    ///
35    /// <details><summary><h4>Gesture</h4></summary>
36    ///
37    ///
38    /// #### `begin`
39    ///  This signal is emitted when the gesture is recognized. This means the
40    /// number of touch sequences matches [`n-points`][struct@crate::Gesture#n-points], and the [`check`][struct@crate::Gesture#check]
41    /// handler(s) returned [`true`].
42    ///
43    /// Note: These conditions may also happen when an extra touch (eg. a third touch
44    /// on a 2-touches gesture) is lifted, in that situation `sequence` won't pertain
45    /// to the current set of active touches, so don't rely on this being true.
46    ///
47    ///
48    ///
49    ///
50    /// #### `cancel`
51    ///  This signal is emitted whenever a sequence is cancelled. This usually
52    /// happens on active touches when [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called
53    /// on `gesture` (manually, due to grabs...), or the individual `sequence`
54    /// was claimed by parent widgets' controllers (see [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
55    ///
56    /// `gesture` must forget everything about `sequence` as a reaction to this signal.
57    ///
58    ///
59    ///
60    ///
61    /// #### `end`
62    ///  This signal is emitted when `gesture` either stopped recognizing the event
63    /// sequences as something to be handled (the [`check`][struct@crate::Gesture#check] handler returned
64    /// [`false`]), or the number of touch sequences became higher or lower than
65    /// [`n-points`][struct@crate::Gesture#n-points].
66    ///
67    /// Note: `sequence` might not pertain to the group of sequences that were
68    /// previously triggering recognition on `gesture` (ie. a just pressed touch
69    /// sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]). This situation may be detected
70    /// by checking through [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
71    ///
72    ///
73    ///
74    ///
75    /// #### `sequence-state-changed`
76    ///  This signal is emitted whenever a sequence state changes. See
77    /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know more about the expectable
78    /// sequence lifetimes.
79    ///
80    ///
81    ///
82    ///
83    /// #### `update`
84    ///  This signal is emitted whenever an event is handled while the gesture is
85    /// recognized. `sequence` is guaranteed to pertain to the set of active touches.
86    ///
87    ///
88    /// </details>
89    ///
90    /// # Implements
91    ///
92    /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`], [`GestureStylusExtManual`][trait@crate::prelude::GestureStylusExtManual]
93    #[doc(alias = "GtkGestureStylus")]
94    pub struct GestureStylus(Object<ffi::GtkGestureStylus, ffi::GtkGestureStylusClass>) @extends GestureSingle, Gesture, EventController;
95
96    match fn {
97        type_ => || ffi::gtk_gesture_stylus_get_type(),
98    }
99}
100
101impl GestureStylus {
102    /// Creates a new [`GestureStylus`][crate::GestureStylus].
103    /// ## `widget`
104    /// a [`Widget`][crate::Widget]
105    ///
106    /// # Returns
107    ///
108    /// a newly created stylus gesture
109    #[doc(alias = "gtk_gesture_stylus_new")]
110    pub fn new(widget: &impl IsA<Widget>) -> GestureStylus {
111        skip_assert_initialized!();
112        unsafe {
113            Gesture::from_glib_full(ffi::gtk_gesture_stylus_new(
114                widget.as_ref().to_glib_none().0,
115            ))
116            .unsafe_cast()
117        }
118    }
119
120    // rustdoc-stripper-ignore-next
121    /// Creates a new builder-pattern struct instance to construct [`GestureStylus`] objects.
122    ///
123    /// This method returns an instance of [`GestureStylusBuilder`](crate::builders::GestureStylusBuilder) which can be used to create [`GestureStylus`] objects.
124    pub fn builder() -> GestureStylusBuilder {
125        GestureStylusBuilder::new()
126    }
127
128    /// Returns the current value for the requested `axis`. This function
129    /// must be called from either the [`down`][struct@crate::GestureStylus#down],
130    /// [`motion`][struct@crate::GestureStylus#motion], [`up`][struct@crate::GestureStylus#up] or [`proximity`][struct@crate::GestureStylus#proximity]
131    /// signals.
132    /// ## `axis`
133    /// requested device axis
134    ///
135    /// # Returns
136    ///
137    /// [`true`] if there is a current value for the axis
138    ///
139    /// ## `value`
140    /// return location for the axis value
141    #[doc(alias = "gtk_gesture_stylus_get_axis")]
142    #[doc(alias = "get_axis")]
143    pub fn axis(&self, axis: gdk::AxisUse) -> Option<f64> {
144        unsafe {
145            let mut value = std::mem::MaybeUninit::uninit();
146            let ret = from_glib(ffi::gtk_gesture_stylus_get_axis(
147                self.to_glib_none().0,
148                axis.into_glib(),
149                value.as_mut_ptr(),
150            ));
151            if ret { Some(value.assume_init()) } else { None }
152        }
153    }
154
155    /// Returns the [`gdk::DeviceTool`][crate::gdk::DeviceTool] currently driving input through this gesture.
156    /// This function must be called from either the [`down`][struct@crate::GestureStylus#down],
157    /// [`motion`][struct@crate::GestureStylus#motion], [`up`][struct@crate::GestureStylus#up] or [`proximity`][struct@crate::GestureStylus#proximity]
158    /// signal handlers.
159    ///
160    /// # Returns
161    ///
162    /// The current stylus tool
163    #[doc(alias = "gtk_gesture_stylus_get_device_tool")]
164    #[doc(alias = "get_device_tool")]
165    pub fn device_tool(&self) -> Option<gdk::DeviceTool> {
166        unsafe {
167            from_glib_none(ffi::gtk_gesture_stylus_get_device_tool(
168                self.to_glib_none().0,
169            ))
170        }
171    }
172
173    #[doc(alias = "down")]
174    pub fn connect_down<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
175        unsafe extern "C" fn down_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
176            this: *mut ffi::GtkGestureStylus,
177            object: std::ffi::c_double,
178            p0: std::ffi::c_double,
179            f: glib::ffi::gpointer,
180        ) {
181            unsafe {
182                let f: &F = &*(f as *const F);
183                f(&from_glib_borrow(this), object, p0)
184            }
185        }
186        unsafe {
187            let f: Box_<F> = Box_::new(f);
188            connect_raw(
189                self.as_ptr() as *mut _,
190                c"down".as_ptr(),
191                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
192                    down_trampoline::<F> as *const (),
193                )),
194                Box_::into_raw(f),
195            )
196        }
197    }
198
199    #[doc(alias = "motion")]
200    pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
201        unsafe extern "C" fn motion_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
202            this: *mut ffi::GtkGestureStylus,
203            object: std::ffi::c_double,
204            p0: std::ffi::c_double,
205            f: glib::ffi::gpointer,
206        ) {
207            unsafe {
208                let f: &F = &*(f as *const F);
209                f(&from_glib_borrow(this), object, p0)
210            }
211        }
212        unsafe {
213            let f: Box_<F> = Box_::new(f);
214            connect_raw(
215                self.as_ptr() as *mut _,
216                c"motion".as_ptr(),
217                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
218                    motion_trampoline::<F> as *const (),
219                )),
220                Box_::into_raw(f),
221            )
222        }
223    }
224
225    #[doc(alias = "proximity")]
226    pub fn connect_proximity<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
227        unsafe extern "C" fn proximity_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
228            this: *mut ffi::GtkGestureStylus,
229            object: std::ffi::c_double,
230            p0: std::ffi::c_double,
231            f: glib::ffi::gpointer,
232        ) {
233            unsafe {
234                let f: &F = &*(f as *const F);
235                f(&from_glib_borrow(this), object, p0)
236            }
237        }
238        unsafe {
239            let f: Box_<F> = Box_::new(f);
240            connect_raw(
241                self.as_ptr() as *mut _,
242                c"proximity".as_ptr(),
243                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
244                    proximity_trampoline::<F> as *const (),
245                )),
246                Box_::into_raw(f),
247            )
248        }
249    }
250
251    #[doc(alias = "up")]
252    pub fn connect_up<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
253        unsafe extern "C" fn up_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
254            this: *mut ffi::GtkGestureStylus,
255            object: std::ffi::c_double,
256            p0: std::ffi::c_double,
257            f: glib::ffi::gpointer,
258        ) {
259            unsafe {
260                let f: &F = &*(f as *const F);
261                f(&from_glib_borrow(this), object, p0)
262            }
263        }
264        unsafe {
265            let f: Box_<F> = Box_::new(f);
266            connect_raw(
267                self.as_ptr() as *mut _,
268                c"up".as_ptr(),
269                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270                    up_trampoline::<F> as *const (),
271                )),
272                Box_::into_raw(f),
273            )
274        }
275    }
276}
277
278#[cfg(feature = "v3_24")]
279#[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
280impl Default for GestureStylus {
281    fn default() -> Self {
282        glib::object::Object::new::<Self>()
283    }
284}
285
286// rustdoc-stripper-ignore-next
287/// A [builder-pattern] type to construct [`GestureStylus`] objects.
288///
289/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
290#[must_use = "The builder must be built to be used"]
291pub struct GestureStylusBuilder {
292    builder: glib::object::ObjectBuilder<'static, GestureStylus>,
293}
294
295impl GestureStylusBuilder {
296    fn new() -> Self {
297        Self {
298            builder: glib::object::Object::builder(),
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 [`GestureStylus`].
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) -> GestureStylus {
359        assert_initialized_main_thread!();
360        self.builder.build()
361    }
362}