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