gtk4/auto/gesture_pan.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::{
6 ffi, EventController, Gesture, GestureDrag, GestureSingle, Orientation, PanDirection,
7 PropagationLimit, PropagationPhase,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// [`GesturePan`][crate::GesturePan] is a [`Gesture`][crate::Gesture] for pan gestures.
19 ///
20 /// These are drags that are locked to happen along one axis. The axis
21 /// that a [`GesturePan`][crate::GesturePan] handles is defined at construct time, and
22 /// can be changed through [`set_orientation()`][Self::set_orientation()].
23 ///
24 /// When the gesture starts to be recognized, [`GesturePan`][crate::GesturePan] will
25 /// attempt to determine as early as possible whether the sequence
26 /// is moving in the expected direction, and denying the sequence if
27 /// this does not happen.
28 ///
29 /// Once a panning gesture along the expected axis is recognized,
30 /// the [`pan`][struct@crate::GesturePan#pan] signal will be emitted as input
31 /// events are received, containing the offset in the given axis.
32 ///
33 /// ## Properties
34 ///
35 ///
36 /// #### `orientation`
37 /// The expected orientation of pan gestures.
38 ///
39 /// Readable | Writeable
40 /// <details><summary><h4>GestureSingle</h4></summary>
41 ///
42 ///
43 /// #### `button`
44 /// Mouse button number to listen to, or 0 to listen for any button.
45 ///
46 /// Readable | Writeable
47 ///
48 ///
49 /// #### `exclusive`
50 /// Whether the gesture is exclusive.
51 ///
52 /// Exclusive gestures only listen to pointer and pointer emulated events.
53 ///
54 /// Readable | Writeable
55 ///
56 ///
57 /// #### `touch-only`
58 /// Whether the gesture handles only touch events.
59 ///
60 /// Readable | Writeable
61 /// </details>
62 /// <details><summary><h4>Gesture</h4></summary>
63 ///
64 ///
65 /// #### `n-points`
66 /// The number of touch points that trigger
67 /// recognition on this gesture.
68 ///
69 /// Readable | Writeable | Construct Only
70 /// </details>
71 /// <details><summary><h4>EventController</h4></summary>
72 ///
73 ///
74 /// #### `name`
75 /// The name for this controller, typically used for debugging purposes.
76 ///
77 /// Readable | Writeable
78 ///
79 ///
80 /// #### `propagation-limit`
81 /// The limit for which events this controller will handle.
82 ///
83 /// Readable | Writeable
84 ///
85 ///
86 /// #### `propagation-phase`
87 /// The propagation phase at which this controller will handle events.
88 ///
89 /// Readable | Writeable
90 ///
91 ///
92 /// #### `widget`
93 /// The widget receiving the `GdkEvents` that the controller will handle.
94 ///
95 /// Readable
96 /// </details>
97 ///
98 /// ## Signals
99 ///
100 ///
101 /// #### `pan`
102 /// Emitted once a panning gesture along the expected axis is detected.
103 ///
104 ///
105 /// <details><summary><h4>GestureDrag</h4></summary>
106 ///
107 ///
108 /// #### `drag-begin`
109 /// Emitted whenever dragging starts.
110 ///
111 ///
112 ///
113 ///
114 /// #### `drag-end`
115 /// Emitted whenever the dragging is finished.
116 ///
117 ///
118 ///
119 ///
120 /// #### `drag-update`
121 /// Emitted whenever the dragging point moves.
122 ///
123 ///
124 /// </details>
125 /// <details><summary><h4>Gesture</h4></summary>
126 ///
127 ///
128 /// #### `begin`
129 /// Emitted when the gesture is recognized.
130 ///
131 /// This means the number of touch sequences matches
132 /// [`n-points`][struct@crate::Gesture#n-points].
133 ///
134 /// Note: These conditions may also happen when an extra touch
135 /// (eg. a third touch on a 2-touches gesture) is lifted, in that
136 /// situation @sequence won't pertain to the current set of active
137 /// touches, so don't rely on this being true.
138 ///
139 ///
140 ///
141 ///
142 /// #### `cancel`
143 /// Emitted whenever a sequence is cancelled.
144 ///
145 /// This usually happens on active touches when
146 /// [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called on @gesture
147 /// (manually, due to grabs...), or the individual @sequence
148 /// was claimed by parent widgets' controllers (see
149 /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
150 ///
151 /// @gesture must forget everything about @sequence as in
152 /// response to this signal.
153 ///
154 ///
155 ///
156 ///
157 /// #### `end`
158 /// Emitted when @gesture either stopped recognizing the event
159 /// sequences as something to be handled, or the number of touch
160 /// sequences became higher or lower than [`n-points`][struct@crate::Gesture#n-points].
161 ///
162 /// Note: @sequence might not pertain to the group of sequences that
163 /// were previously triggering recognition on @gesture (ie. a just
164 /// pressed touch sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]).
165 /// This situation may be detected by checking through
166 /// [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
167 ///
168 ///
169 ///
170 ///
171 /// #### `sequence-state-changed`
172 /// Emitted whenever a sequence state changes.
173 ///
174 /// See [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know
175 /// more about the expectable sequence lifetimes.
176 ///
177 ///
178 ///
179 ///
180 /// #### `update`
181 /// Emitted whenever an event is handled while the gesture is recognized.
182 ///
183 /// @sequence is guaranteed to pertain to the set of active touches.
184 ///
185 ///
186 /// </details>
187 ///
188 /// # Implements
189 ///
190 /// [`GestureDragExt`][trait@crate::prelude::GestureDragExt], [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
191 #[doc(alias = "GtkGesturePan")]
192 pub struct GesturePan(Object<ffi::GtkGesturePan, ffi::GtkGesturePanClass>) @extends GestureDrag, GestureSingle, Gesture, EventController;
193
194 match fn {
195 type_ => || ffi::gtk_gesture_pan_get_type(),
196 }
197}
198
199impl GesturePan {
200 /// Returns a newly created [`Gesture`][crate::Gesture] that recognizes pan gestures.
201 /// ## `orientation`
202 /// expected orientation
203 ///
204 /// # Returns
205 ///
206 /// a newly created [`GesturePan`][crate::GesturePan]
207 #[doc(alias = "gtk_gesture_pan_new")]
208 pub fn new(orientation: Orientation) -> GesturePan {
209 assert_initialized_main_thread!();
210 unsafe {
211 Gesture::from_glib_full(ffi::gtk_gesture_pan_new(orientation.into_glib())).unsafe_cast()
212 }
213 }
214
215 // rustdoc-stripper-ignore-next
216 /// Creates a new builder-pattern struct instance to construct [`GesturePan`] objects.
217 ///
218 /// This method returns an instance of [`GesturePanBuilder`](crate::builders::GesturePanBuilder) which can be used to create [`GesturePan`] objects.
219 pub fn builder() -> GesturePanBuilder {
220 GesturePanBuilder::new()
221 }
222
223 /// Returns the orientation of the pan gestures that this @self expects.
224 ///
225 /// # Returns
226 ///
227 /// the expected orientation for pan gestures
228 #[doc(alias = "gtk_gesture_pan_get_orientation")]
229 #[doc(alias = "get_orientation")]
230 pub fn orientation(&self) -> Orientation {
231 unsafe { from_glib(ffi::gtk_gesture_pan_get_orientation(self.to_glib_none().0)) }
232 }
233
234 /// Sets the orientation to be expected on pan gestures.
235 /// ## `orientation`
236 /// expected orientation
237 #[doc(alias = "gtk_gesture_pan_set_orientation")]
238 #[doc(alias = "orientation")]
239 pub fn set_orientation(&self, orientation: Orientation) {
240 unsafe {
241 ffi::gtk_gesture_pan_set_orientation(self.to_glib_none().0, orientation.into_glib());
242 }
243 }
244
245 /// Emitted once a panning gesture along the expected axis is detected.
246 /// ## `direction`
247 /// current direction of the pan gesture
248 /// ## `offset`
249 /// Offset along the gesture orientation
250 #[doc(alias = "pan")]
251 pub fn connect_pan<F: Fn(&Self, PanDirection, f64) + 'static>(&self, f: F) -> SignalHandlerId {
252 unsafe extern "C" fn pan_trampoline<F: Fn(&GesturePan, PanDirection, f64) + 'static>(
253 this: *mut ffi::GtkGesturePan,
254 direction: ffi::GtkPanDirection,
255 offset: std::ffi::c_double,
256 f: glib::ffi::gpointer,
257 ) {
258 let f: &F = &*(f as *const F);
259 f(&from_glib_borrow(this), from_glib(direction), offset)
260 }
261 unsafe {
262 let f: Box_<F> = Box_::new(f);
263 connect_raw(
264 self.as_ptr() as *mut _,
265 b"pan\0".as_ptr() as *const _,
266 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
267 pan_trampoline::<F> as *const (),
268 )),
269 Box_::into_raw(f),
270 )
271 }
272 }
273
274 #[doc(alias = "orientation")]
275 pub fn connect_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
276 unsafe extern "C" fn notify_orientation_trampoline<F: Fn(&GesturePan) + 'static>(
277 this: *mut ffi::GtkGesturePan,
278 _param_spec: glib::ffi::gpointer,
279 f: glib::ffi::gpointer,
280 ) {
281 let f: &F = &*(f as *const F);
282 f(&from_glib_borrow(this))
283 }
284 unsafe {
285 let f: Box_<F> = Box_::new(f);
286 connect_raw(
287 self.as_ptr() as *mut _,
288 b"notify::orientation\0".as_ptr() as *const _,
289 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290 notify_orientation_trampoline::<F> as *const (),
291 )),
292 Box_::into_raw(f),
293 )
294 }
295 }
296}
297
298impl Default for GesturePan {
299 fn default() -> Self {
300 glib::object::Object::new::<Self>()
301 }
302}
303
304// rustdoc-stripper-ignore-next
305/// A [builder-pattern] type to construct [`GesturePan`] objects.
306///
307/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
308#[must_use = "The builder must be built to be used"]
309pub struct GesturePanBuilder {
310 builder: glib::object::ObjectBuilder<'static, GesturePan>,
311}
312
313impl GesturePanBuilder {
314 fn new() -> Self {
315 Self {
316 builder: glib::object::Object::builder(),
317 }
318 }
319
320 /// The expected orientation of pan gestures.
321 pub fn orientation(self, orientation: Orientation) -> Self {
322 Self {
323 builder: self.builder.property("orientation", orientation),
324 }
325 }
326
327 /// Mouse button number to listen to, or 0 to listen for any button.
328 pub fn button(self, button: u32) -> Self {
329 Self {
330 builder: self.builder.property("button", button),
331 }
332 }
333
334 /// Whether the gesture is exclusive.
335 ///
336 /// Exclusive gestures only listen to pointer and pointer emulated events.
337 pub fn exclusive(self, exclusive: bool) -> Self {
338 Self {
339 builder: self.builder.property("exclusive", exclusive),
340 }
341 }
342
343 /// Whether the gesture handles only touch events.
344 pub fn touch_only(self, touch_only: bool) -> Self {
345 Self {
346 builder: self.builder.property("touch-only", touch_only),
347 }
348 }
349
350 /// The number of touch points that trigger
351 /// recognition on this gesture.
352 pub fn n_points(self, n_points: u32) -> Self {
353 Self {
354 builder: self.builder.property("n-points", n_points),
355 }
356 }
357
358 /// The name for this controller, typically used for debugging purposes.
359 pub fn name(self, name: impl Into<glib::GString>) -> Self {
360 Self {
361 builder: self.builder.property("name", name.into()),
362 }
363 }
364
365 /// The limit for which events this controller will handle.
366 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
367 Self {
368 builder: self
369 .builder
370 .property("propagation-limit", propagation_limit),
371 }
372 }
373
374 /// The propagation phase at which this controller will handle events.
375 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
376 Self {
377 builder: self
378 .builder
379 .property("propagation-phase", propagation_phase),
380 }
381 }
382
383 // rustdoc-stripper-ignore-next
384 /// Build the [`GesturePan`].
385 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
386 pub fn build(self) -> GesturePan {
387 assert_initialized_main_thread!();
388 self.builder.build()
389 }
390}