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