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, 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 /// Returns the current value for the requested `axis`. This function
121 /// must be called from either the [`down`][struct@crate::GestureStylus#down],
122 /// [`motion`][struct@crate::GestureStylus#motion], [`up`][struct@crate::GestureStylus#up] or [`proximity`][struct@crate::GestureStylus#proximity]
123 /// signals.
124 /// ## `axis`
125 /// requested device axis
126 ///
127 /// # Returns
128 ///
129 /// [`true`] if there is a current value for the axis
130 ///
131 /// ## `value`
132 /// return location for the axis value
133 #[doc(alias = "gtk_gesture_stylus_get_axis")]
134 #[doc(alias = "get_axis")]
135 pub fn axis(&self, axis: gdk::AxisUse) -> Option<f64> {
136 unsafe {
137 let mut value = std::mem::MaybeUninit::uninit();
138 let ret = from_glib(ffi::gtk_gesture_stylus_get_axis(
139 self.to_glib_none().0,
140 axis.into_glib(),
141 value.as_mut_ptr(),
142 ));
143 if ret { Some(value.assume_init()) } else { None }
144 }
145 }
146
147 /// Returns the [`gdk::DeviceTool`][crate::gdk::DeviceTool] currently driving input through this gesture.
148 /// This function must be called from either the [`down`][struct@crate::GestureStylus#down],
149 /// [`motion`][struct@crate::GestureStylus#motion], [`up`][struct@crate::GestureStylus#up] or [`proximity`][struct@crate::GestureStylus#proximity]
150 /// signal handlers.
151 ///
152 /// # Returns
153 ///
154 /// The current stylus tool
155 #[doc(alias = "gtk_gesture_stylus_get_device_tool")]
156 #[doc(alias = "get_device_tool")]
157 pub fn device_tool(&self) -> Option<gdk::DeviceTool> {
158 unsafe {
159 from_glib_none(ffi::gtk_gesture_stylus_get_device_tool(
160 self.to_glib_none().0,
161 ))
162 }
163 }
164
165 #[doc(alias = "down")]
166 pub fn connect_down<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
167 unsafe extern "C" fn down_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
168 this: *mut ffi::GtkGestureStylus,
169 object: std::ffi::c_double,
170 p0: std::ffi::c_double,
171 f: glib::ffi::gpointer,
172 ) {
173 unsafe {
174 let f: &F = &*(f as *const F);
175 f(&from_glib_borrow(this), object, p0)
176 }
177 }
178 unsafe {
179 let f: Box_<F> = Box_::new(f);
180 connect_raw(
181 self.as_ptr() as *mut _,
182 c"down".as_ptr(),
183 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
184 down_trampoline::<F> as *const (),
185 )),
186 Box_::into_raw(f),
187 )
188 }
189 }
190
191 #[doc(alias = "motion")]
192 pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
193 unsafe extern "C" fn motion_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
194 this: *mut ffi::GtkGestureStylus,
195 object: std::ffi::c_double,
196 p0: std::ffi::c_double,
197 f: glib::ffi::gpointer,
198 ) {
199 unsafe {
200 let f: &F = &*(f as *const F);
201 f(&from_glib_borrow(this), object, p0)
202 }
203 }
204 unsafe {
205 let f: Box_<F> = Box_::new(f);
206 connect_raw(
207 self.as_ptr() as *mut _,
208 c"motion".as_ptr(),
209 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
210 motion_trampoline::<F> as *const (),
211 )),
212 Box_::into_raw(f),
213 )
214 }
215 }
216
217 #[doc(alias = "proximity")]
218 pub fn connect_proximity<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
219 unsafe extern "C" fn proximity_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
220 this: *mut ffi::GtkGestureStylus,
221 object: std::ffi::c_double,
222 p0: std::ffi::c_double,
223 f: glib::ffi::gpointer,
224 ) {
225 unsafe {
226 let f: &F = &*(f as *const F);
227 f(&from_glib_borrow(this), object, p0)
228 }
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"proximity".as_ptr(),
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 proximity_trampoline::<F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242
243 #[doc(alias = "up")]
244 pub fn connect_up<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
245 unsafe extern "C" fn up_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
246 this: *mut ffi::GtkGestureStylus,
247 object: std::ffi::c_double,
248 p0: std::ffi::c_double,
249 f: glib::ffi::gpointer,
250 ) {
251 unsafe {
252 let f: &F = &*(f as *const F);
253 f(&from_glib_borrow(this), object, p0)
254 }
255 }
256 unsafe {
257 let f: Box_<F> = Box_::new(f);
258 connect_raw(
259 self.as_ptr() as *mut _,
260 c"up".as_ptr(),
261 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
262 up_trampoline::<F> as *const (),
263 )),
264 Box_::into_raw(f),
265 )
266 }
267 }
268}