gtk/auto/gesture_swipe.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, PropagationPhase, 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 /// [`GestureSwipe`][crate::GestureSwipe] is a [`Gesture`][crate::Gesture] implementation able to recognize
15 /// swipes, after a press/move/.../move/release sequence happens, the
16 /// [`swipe`][struct@crate::GestureSwipe#swipe] signal will be emitted, providing the velocity
17 /// and directionality of the sequence at the time it was lifted.
18 ///
19 /// If the velocity is desired in intermediate points,
20 /// [`velocity()`][Self::velocity()] can be called on eg. a
21 /// [`update`][struct@crate::Gesture#update] handler.
22 ///
23 /// All velocities are reported in pixels/sec units.
24 ///
25 /// ## Signals
26 ///
27 ///
28 /// #### `swipe`
29 /// This signal is emitted when the recognized gesture is finished, velocity
30 /// and direction are a product of previously recorded events.
31 ///
32 ///
33 /// <details><summary><h4>Gesture</h4></summary>
34 ///
35 ///
36 /// #### `begin`
37 /// This signal is emitted when the gesture is recognized. This means the
38 /// number of touch sequences matches [`n-points`][struct@crate::Gesture#n-points], and the [`check`][struct@crate::Gesture#check]
39 /// handler(s) returned [`true`].
40 ///
41 /// Note: These conditions may also happen when an extra touch (eg. a third touch
42 /// on a 2-touches gesture) is lifted, in that situation `sequence` won't pertain
43 /// to the current set of active touches, so don't rely on this being true.
44 ///
45 ///
46 ///
47 ///
48 /// #### `cancel`
49 /// This signal is emitted whenever a sequence is cancelled. This usually
50 /// happens on active touches when [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called
51 /// on `gesture` (manually, due to grabs...), or the individual `sequence`
52 /// was claimed by parent widgets' controllers (see [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
53 ///
54 /// `gesture` must forget everything about `sequence` as a reaction to this signal.
55 ///
56 ///
57 ///
58 ///
59 /// #### `end`
60 /// This signal is emitted when `gesture` either stopped recognizing the event
61 /// sequences as something to be handled (the [`check`][struct@crate::Gesture#check] handler returned
62 /// [`false`]), or the number of touch sequences became higher or lower than
63 /// [`n-points`][struct@crate::Gesture#n-points].
64 ///
65 /// Note: `sequence` might not pertain to the group of sequences that were
66 /// previously triggering recognition on `gesture` (ie. a just pressed touch
67 /// sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]). This situation may be detected
68 /// by checking through [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
69 ///
70 ///
71 ///
72 ///
73 /// #### `sequence-state-changed`
74 /// This signal is emitted whenever a sequence state changes. See
75 /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know more about the expectable
76 /// sequence lifetimes.
77 ///
78 ///
79 ///
80 ///
81 /// #### `update`
82 /// This signal is emitted whenever an event is handled while the gesture is
83 /// recognized. `sequence` is guaranteed to pertain to the set of active touches.
84 ///
85 ///
86 /// </details>
87 ///
88 /// # Implements
89 ///
90 /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
91 #[doc(alias = "GtkGestureSwipe")]
92 pub struct GestureSwipe(Object<ffi::GtkGestureSwipe, ffi::GtkGestureSwipeClass>) @extends GestureSingle, Gesture, EventController;
93
94 match fn {
95 type_ => || ffi::gtk_gesture_swipe_get_type(),
96 }
97}
98
99impl GestureSwipe {
100 /// Returns a newly created [`Gesture`][crate::Gesture] that recognizes swipes.
101 /// ## `widget`
102 /// a [`Widget`][crate::Widget]
103 ///
104 /// # Returns
105 ///
106 /// a newly created [`GestureSwipe`][crate::GestureSwipe]
107 #[doc(alias = "gtk_gesture_swipe_new")]
108 pub fn new(widget: &impl IsA<Widget>) -> GestureSwipe {
109 skip_assert_initialized!();
110 unsafe {
111 Gesture::from_glib_full(ffi::gtk_gesture_swipe_new(widget.as_ref().to_glib_none().0))
112 .unsafe_cast()
113 }
114 }
115
116 // rustdoc-stripper-ignore-next
117 /// Creates a new builder-pattern struct instance to construct [`GestureSwipe`] objects.
118 ///
119 /// This method returns an instance of [`GestureSwipeBuilder`](crate::builders::GestureSwipeBuilder) which can be used to create [`GestureSwipe`] objects.
120 pub fn builder() -> GestureSwipeBuilder {
121 GestureSwipeBuilder::new()
122 }
123
124 /// If the gesture is recognized, this function returns [`true`] and fill in
125 /// `velocity_x` and `velocity_y` with the recorded velocity, as per the
126 /// last event(s) processed.
127 ///
128 /// # Returns
129 ///
130 /// whether velocity could be calculated
131 ///
132 /// ## `velocity_x`
133 /// return value for the velocity in the X axis, in pixels/sec
134 ///
135 /// ## `velocity_y`
136 /// return value for the velocity in the Y axis, in pixels/sec
137 #[doc(alias = "gtk_gesture_swipe_get_velocity")]
138 #[doc(alias = "get_velocity")]
139 pub fn velocity(&self) -> Option<(f64, f64)> {
140 unsafe {
141 let mut velocity_x = mem::MaybeUninit::uninit();
142 let mut velocity_y = mem::MaybeUninit::uninit();
143 let ret = from_glib(ffi::gtk_gesture_swipe_get_velocity(
144 self.to_glib_none().0,
145 velocity_x.as_mut_ptr(),
146 velocity_y.as_mut_ptr(),
147 ));
148 if ret {
149 Some((velocity_x.assume_init(), velocity_y.assume_init()))
150 } else {
151 None
152 }
153 }
154 }
155
156 /// This signal is emitted when the recognized gesture is finished, velocity
157 /// and direction are a product of previously recorded events.
158 /// ## `velocity_x`
159 /// velocity in the X axis, in pixels/sec
160 /// ## `velocity_y`
161 /// velocity in the Y axis, in pixels/sec
162 #[doc(alias = "swipe")]
163 pub fn connect_swipe<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
164 unsafe extern "C" fn swipe_trampoline<F: Fn(&GestureSwipe, f64, f64) + 'static>(
165 this: *mut ffi::GtkGestureSwipe,
166 velocity_x: libc::c_double,
167 velocity_y: libc::c_double,
168 f: glib::ffi::gpointer,
169 ) {
170 let f: &F = &*(f as *const F);
171 f(&from_glib_borrow(this), velocity_x, velocity_y)
172 }
173 unsafe {
174 let f: Box_<F> = Box_::new(f);
175 connect_raw(
176 self.as_ptr() as *mut _,
177 b"swipe\0".as_ptr() as *const _,
178 Some(transmute::<_, unsafe extern "C" fn()>(
179 swipe_trampoline::<F> as *const (),
180 )),
181 Box_::into_raw(f),
182 )
183 }
184 }
185}
186
187impl Default for GestureSwipe {
188 fn default() -> Self {
189 glib::object::Object::new::<Self>()
190 }
191}
192
193// rustdoc-stripper-ignore-next
194/// A [builder-pattern] type to construct [`GestureSwipe`] objects.
195///
196/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
197#[must_use = "The builder must be built to be used"]
198pub struct GestureSwipeBuilder {
199 builder: glib::object::ObjectBuilder<'static, GestureSwipe>,
200}
201
202impl GestureSwipeBuilder {
203 fn new() -> Self {
204 Self {
205 builder: glib::object::Object::builder(),
206 }
207 }
208
209 /// Mouse button number to listen to, or 0 to listen for any button.
210 pub fn button(self, button: u32) -> Self {
211 Self {
212 builder: self.builder.property("button", button),
213 }
214 }
215
216 /// Whether the gesture is exclusive. Exclusive gestures only listen to pointer
217 /// and pointer emulated events.
218 pub fn exclusive(self, exclusive: bool) -> Self {
219 Self {
220 builder: self.builder.property("exclusive", exclusive),
221 }
222 }
223
224 /// Whether the gesture handles only touch events.
225 pub fn touch_only(self, touch_only: bool) -> Self {
226 Self {
227 builder: self.builder.property("touch-only", touch_only),
228 }
229 }
230
231 /// The number of touch points that trigger recognition on this gesture,
232 pub fn n_points(self, n_points: u32) -> Self {
233 Self {
234 builder: self.builder.property("n-points", n_points),
235 }
236 }
237
238 /// If non-[`None`], the gesture will only listen for events that happen on
239 /// this [`gdk::Window`][crate::gdk::Window], or a child of it.
240 pub fn window(self, window: &gdk::Window) -> Self {
241 Self {
242 builder: self.builder.property("window", window.clone()),
243 }
244 }
245
246 /// The propagation phase at which this controller will handle events.
247 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
248 Self {
249 builder: self
250 .builder
251 .property("propagation-phase", propagation_phase),
252 }
253 }
254
255 /// The widget receiving the `GdkEvents` that the controller will handle.
256 pub fn widget(self, widget: &impl IsA<Widget>) -> Self {
257 Self {
258 builder: self.builder.property("widget", widget.clone().upcast()),
259 }
260 }
261
262 // rustdoc-stripper-ignore-next
263 /// Build the [`GestureSwipe`].
264 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
265 pub fn build(self) -> GestureSwipe {
266 self.builder.build()
267 }
268}
269
270impl fmt::Display for GestureSwipe {
271 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
272 f.write_str("GestureSwipe")
273 }
274}