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