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