gtk/auto/gesture_multi_press.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::transmute};
12
13glib::wrapper! {
14 /// [`GestureMultiPress`][crate::GestureMultiPress] is a [`Gesture`][crate::Gesture] implementation able to recognize
15 /// multiple clicks on a nearby zone, which can be listened for through the
16 /// [`pressed`][struct@crate::GestureMultiPress#pressed] signal. Whenever time or distance between
17 /// clicks exceed the GTK+ defaults, [`stopped`][struct@crate::GestureMultiPress#stopped] is emitted,
18 /// and the click counter is reset.
19 ///
20 /// Callers may also restrict the area that is considered valid for a >1
21 /// touch/button press through [`set_area()`][Self::set_area()], so any
22 /// click happening outside that area is considered to be a first click of
23 /// its own.
24 ///
25 /// ## Signals
26 ///
27 ///
28 /// #### `pressed`
29 /// This signal is emitted whenever a button or touch press happens.
30 ///
31 ///
32 ///
33 ///
34 /// #### `released`
35 /// This signal is emitted when a button or touch is released. `n_press`
36 /// will report the number of press that is paired to this event, note
37 /// that [`stopped`][struct@crate::GestureMultiPress#stopped] may have been emitted between the
38 /// press and its release, `n_press` will only start over at the next press.
39 ///
40 ///
41 ///
42 ///
43 /// #### `stopped`
44 /// This signal is emitted whenever any time/distance threshold has
45 /// been exceeded.
46 ///
47 ///
48 /// <details><summary><h4>Gesture</h4></summary>
49 ///
50 ///
51 /// #### `begin`
52 /// This signal is emitted when the gesture is recognized. This means the
53 /// number of touch sequences matches [`n-points`][struct@crate::Gesture#n-points], and the [`check`][struct@crate::Gesture#check]
54 /// handler(s) returned [`true`].
55 ///
56 /// Note: These conditions may also happen when an extra touch (eg. a third touch
57 /// on a 2-touches gesture) is lifted, in that situation `sequence` won't pertain
58 /// to the current set of active touches, so don't rely on this being true.
59 ///
60 ///
61 ///
62 ///
63 /// #### `cancel`
64 /// This signal is emitted whenever a sequence is cancelled. This usually
65 /// happens on active touches when [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called
66 /// on `gesture` (manually, due to grabs...), or the individual `sequence`
67 /// was claimed by parent widgets' controllers (see [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
68 ///
69 /// `gesture` must forget everything about `sequence` as a reaction to this signal.
70 ///
71 ///
72 ///
73 ///
74 /// #### `end`
75 /// This signal is emitted when `gesture` either stopped recognizing the event
76 /// sequences as something to be handled (the [`check`][struct@crate::Gesture#check] handler returned
77 /// [`false`]), or the number of touch sequences became higher or lower than
78 /// [`n-points`][struct@crate::Gesture#n-points].
79 ///
80 /// Note: `sequence` might not pertain to the group of sequences that were
81 /// previously triggering recognition on `gesture` (ie. a just pressed touch
82 /// sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]). This situation may be detected
83 /// by checking through [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
84 ///
85 ///
86 ///
87 ///
88 /// #### `sequence-state-changed`
89 /// This signal is emitted whenever a sequence state changes. See
90 /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know more about the expectable
91 /// sequence lifetimes.
92 ///
93 ///
94 ///
95 ///
96 /// #### `update`
97 /// This signal is emitted whenever an event is handled while the gesture is
98 /// recognized. `sequence` is guaranteed to pertain to the set of active touches.
99 ///
100 ///
101 /// </details>
102 ///
103 /// # Implements
104 ///
105 /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
106 #[doc(alias = "GtkGestureMultiPress")]
107 pub struct GestureMultiPress(Object<ffi::GtkGestureMultiPress, ffi::GtkGestureMultiPressClass>) @extends GestureSingle, Gesture, EventController;
108
109 match fn {
110 type_ => || ffi::gtk_gesture_multi_press_get_type(),
111 }
112}
113
114impl GestureMultiPress {
115 /// Returns a newly created [`Gesture`][crate::Gesture] that recognizes single and multiple
116 /// presses.
117 /// ## `widget`
118 /// a [`Widget`][crate::Widget]
119 ///
120 /// # Returns
121 ///
122 /// a newly created [`GestureMultiPress`][crate::GestureMultiPress]
123 #[doc(alias = "gtk_gesture_multi_press_new")]
124 pub fn new(widget: &impl IsA<Widget>) -> GestureMultiPress {
125 skip_assert_initialized!();
126 unsafe {
127 Gesture::from_glib_full(ffi::gtk_gesture_multi_press_new(
128 widget.as_ref().to_glib_none().0,
129 ))
130 .unsafe_cast()
131 }
132 }
133
134 // rustdoc-stripper-ignore-next
135 /// Creates a new builder-pattern struct instance to construct [`GestureMultiPress`] objects.
136 ///
137 /// This method returns an instance of [`GestureMultiPressBuilder`](crate::builders::GestureMultiPressBuilder) which can be used to create [`GestureMultiPress`] objects.
138 pub fn builder() -> GestureMultiPressBuilder {
139 GestureMultiPressBuilder::new()
140 }
141
142 /// If an area was set through [`set_area()`][Self::set_area()],
143 /// this function will return [`true`] and fill in `rect` with the
144 /// press area. See [`set_area()`][Self::set_area()] for more
145 /// details on what the press area represents.
146 ///
147 /// # Returns
148 ///
149 /// [`true`] if `rect` was filled with the press area
150 ///
151 /// ## `rect`
152 /// return location for the press area
153 #[doc(alias = "gtk_gesture_multi_press_get_area")]
154 #[doc(alias = "get_area")]
155 pub fn area(&self) -> Option<gdk::Rectangle> {
156 unsafe {
157 let mut rect = gdk::Rectangle::uninitialized();
158 let ret = from_glib(ffi::gtk_gesture_multi_press_get_area(
159 self.to_glib_none().0,
160 rect.to_glib_none_mut().0,
161 ));
162 if ret {
163 Some(rect)
164 } else {
165 None
166 }
167 }
168 }
169
170 /// If `rect` is non-[`None`], the press area will be checked to be
171 /// confined within the rectangle, otherwise the button count
172 /// will be reset so the press is seen as being the first one.
173 /// If `rect` is [`None`], the area will be reset to an unrestricted
174 /// state.
175 ///
176 /// Note: The rectangle is only used to determine whether any
177 /// non-first click falls within the expected area. This is not
178 /// akin to an input shape.
179 /// ## `rect`
180 /// rectangle to receive coordinates on
181 #[doc(alias = "gtk_gesture_multi_press_set_area")]
182 pub fn set_area(&self, rect: Option<&gdk::Rectangle>) {
183 unsafe {
184 ffi::gtk_gesture_multi_press_set_area(self.to_glib_none().0, rect.to_glib_none().0);
185 }
186 }
187
188 /// This signal is emitted whenever a button or touch press happens.
189 /// ## `n_press`
190 /// how many touch/button presses happened with this one
191 /// ## `x`
192 /// The X coordinate, in widget allocation coordinates
193 /// ## `y`
194 /// The Y coordinate, in widget allocation coordinates
195 #[doc(alias = "pressed")]
196 pub fn connect_pressed<F: Fn(&Self, i32, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
197 unsafe extern "C" fn pressed_trampoline<
198 F: Fn(&GestureMultiPress, i32, f64, f64) + 'static,
199 >(
200 this: *mut ffi::GtkGestureMultiPress,
201 n_press: libc::c_int,
202 x: libc::c_double,
203 y: libc::c_double,
204 f: glib::ffi::gpointer,
205 ) {
206 let f: &F = &*(f as *const F);
207 f(&from_glib_borrow(this), n_press, x, y)
208 }
209 unsafe {
210 let f: Box_<F> = Box_::new(f);
211 connect_raw(
212 self.as_ptr() as *mut _,
213 b"pressed\0".as_ptr() as *const _,
214 Some(transmute::<_, unsafe extern "C" fn()>(
215 pressed_trampoline::<F> as *const (),
216 )),
217 Box_::into_raw(f),
218 )
219 }
220 }
221
222 /// This signal is emitted when a button or touch is released. `n_press`
223 /// will report the number of press that is paired to this event, note
224 /// that [`stopped`][struct@crate::GestureMultiPress#stopped] may have been emitted between the
225 /// press and its release, `n_press` will only start over at the next press.
226 /// ## `n_press`
227 /// number of press that is paired with this release
228 /// ## `x`
229 /// The X coordinate, in widget allocation coordinates
230 /// ## `y`
231 /// The Y coordinate, in widget allocation coordinates
232 #[doc(alias = "released")]
233 pub fn connect_released<F: Fn(&Self, i32, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
234 unsafe extern "C" fn released_trampoline<
235 F: Fn(&GestureMultiPress, i32, f64, f64) + 'static,
236 >(
237 this: *mut ffi::GtkGestureMultiPress,
238 n_press: libc::c_int,
239 x: libc::c_double,
240 y: libc::c_double,
241 f: glib::ffi::gpointer,
242 ) {
243 let f: &F = &*(f as *const F);
244 f(&from_glib_borrow(this), n_press, x, y)
245 }
246 unsafe {
247 let f: Box_<F> = Box_::new(f);
248 connect_raw(
249 self.as_ptr() as *mut _,
250 b"released\0".as_ptr() as *const _,
251 Some(transmute::<_, unsafe extern "C" fn()>(
252 released_trampoline::<F> as *const (),
253 )),
254 Box_::into_raw(f),
255 )
256 }
257 }
258
259 /// This signal is emitted whenever any time/distance threshold has
260 /// been exceeded.
261 #[doc(alias = "stopped")]
262 pub fn connect_stopped<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
263 unsafe extern "C" fn stopped_trampoline<F: Fn(&GestureMultiPress) + 'static>(
264 this: *mut ffi::GtkGestureMultiPress,
265 f: glib::ffi::gpointer,
266 ) {
267 let f: &F = &*(f as *const F);
268 f(&from_glib_borrow(this))
269 }
270 unsafe {
271 let f: Box_<F> = Box_::new(f);
272 connect_raw(
273 self.as_ptr() as *mut _,
274 b"stopped\0".as_ptr() as *const _,
275 Some(transmute::<_, unsafe extern "C" fn()>(
276 stopped_trampoline::<F> as *const (),
277 )),
278 Box_::into_raw(f),
279 )
280 }
281 }
282}
283
284impl Default for GestureMultiPress {
285 fn default() -> Self {
286 glib::object::Object::new::<Self>()
287 }
288}
289
290// rustdoc-stripper-ignore-next
291/// A [builder-pattern] type to construct [`GestureMultiPress`] objects.
292///
293/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
294#[must_use = "The builder must be built to be used"]
295pub struct GestureMultiPressBuilder {
296 builder: glib::object::ObjectBuilder<'static, GestureMultiPress>,
297}
298
299impl GestureMultiPressBuilder {
300 fn new() -> Self {
301 Self {
302 builder: glib::object::Object::builder(),
303 }
304 }
305
306 /// Mouse button number to listen to, or 0 to listen for any button.
307 pub fn button(self, button: u32) -> Self {
308 Self {
309 builder: self.builder.property("button", button),
310 }
311 }
312
313 /// Whether the gesture is exclusive. Exclusive gestures only listen to pointer
314 /// and pointer emulated events.
315 pub fn exclusive(self, exclusive: bool) -> Self {
316 Self {
317 builder: self.builder.property("exclusive", exclusive),
318 }
319 }
320
321 /// Whether the gesture handles only touch events.
322 pub fn touch_only(self, touch_only: bool) -> Self {
323 Self {
324 builder: self.builder.property("touch-only", touch_only),
325 }
326 }
327
328 /// The number of touch points that trigger recognition on this gesture,
329 pub fn n_points(self, n_points: u32) -> Self {
330 Self {
331 builder: self.builder.property("n-points", n_points),
332 }
333 }
334
335 /// If non-[`None`], the gesture will only listen for events that happen on
336 /// this [`gdk::Window`][crate::gdk::Window], or a child of it.
337 pub fn window(self, window: &gdk::Window) -> Self {
338 Self {
339 builder: self.builder.property("window", window.clone()),
340 }
341 }
342
343 /// The propagation phase at which this controller will handle events.
344 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
345 Self {
346 builder: self
347 .builder
348 .property("propagation-phase", propagation_phase),
349 }
350 }
351
352 /// The widget receiving the `GdkEvents` that the controller will handle.
353 pub fn widget(self, widget: &impl IsA<Widget>) -> Self {
354 Self {
355 builder: self.builder.property("widget", widget.clone().upcast()),
356 }
357 }
358
359 // rustdoc-stripper-ignore-next
360 /// Build the [`GestureMultiPress`].
361 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
362 pub fn build(self) -> GestureMultiPress {
363 self.builder.build()
364 }
365}
366
367impl fmt::Display for GestureMultiPress {
368 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
369 f.write_str("GestureMultiPress")
370 }
371}