gtk4/auto/gesture_rotate.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, PropagationLimit, PropagationPhase, 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 /// Recognizes 2-finger rotation gestures.
16 ///
17 /// Whenever the angle between both handled sequences changes, the
18 /// [`angle-changed`][struct@crate::GestureRotate#angle-changed] signal is emitted.
19 ///
20 /// ## Signals
21 ///
22 ///
23 /// #### `angle-changed`
24 /// Emitted when the angle between both tracked points changes.
25 ///
26 ///
27 /// <details><summary><h4>Gesture</h4></summary>
28 ///
29 ///
30 /// #### `begin`
31 /// Emitted when the gesture is recognized.
32 ///
33 /// This means the number of touch sequences matches
34 /// [`n-points`][struct@crate::Gesture#n-points].
35 ///
36 /// Note: These conditions may also happen when an extra touch
37 /// (eg. a third touch on a 2-touches gesture) is lifted, in that
38 /// situation @sequence won't pertain to the current set of active
39 /// touches, so don't rely on this being true.
40 ///
41 ///
42 ///
43 ///
44 /// #### `cancel`
45 /// Emitted whenever a sequence is cancelled.
46 ///
47 /// This usually happens on active touches when
48 /// [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called on @gesture
49 /// (manually, due to grabs...), or the individual @sequence
50 /// was claimed by parent widgets' controllers (see
51 /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
52 ///
53 /// @gesture must forget everything about @sequence as in
54 /// response to this signal.
55 ///
56 ///
57 ///
58 ///
59 /// #### `end`
60 /// Emitted when @gesture either stopped recognizing the event
61 /// sequences as something to be handled, or the number of touch
62 /// sequences became higher or lower than [`n-points`][struct@crate::Gesture#n-points].
63 ///
64 /// Note: @sequence might not pertain to the group of sequences that
65 /// were previously triggering recognition on @gesture (ie. a just
66 /// pressed touch sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]).
67 /// This situation may be detected by checking through
68 /// [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
69 ///
70 ///
71 ///
72 ///
73 /// #### `sequence-state-changed`
74 /// Emitted whenever a sequence state changes.
75 ///
76 /// See [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know
77 /// more about the expectable sequence lifetimes.
78 ///
79 ///
80 ///
81 ///
82 /// #### `update`
83 /// Emitted whenever an event is handled while the gesture is recognized.
84 ///
85 /// @sequence is guaranteed to pertain to the set of active touches.
86 ///
87 ///
88 /// </details>
89 ///
90 /// # Implements
91 ///
92 /// [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`], [`EventControllerExtManual`][trait@crate::prelude::EventControllerExtManual]
93 #[doc(alias = "GtkGestureRotate")]
94 pub struct GestureRotate(Object<ffi::GtkGestureRotate, ffi::GtkGestureRotateClass>) @extends Gesture, EventController;
95
96 match fn {
97 type_ => || ffi::gtk_gesture_rotate_get_type(),
98 }
99}
100
101impl GestureRotate {
102 /// Returns a newly created [`Gesture`][crate::Gesture] that recognizes 2-touch
103 /// rotation gestures.
104 ///
105 /// # Returns
106 ///
107 /// a newly created [`GestureRotate`][crate::GestureRotate]
108 #[doc(alias = "gtk_gesture_rotate_new")]
109 pub fn new() -> GestureRotate {
110 assert_initialized_main_thread!();
111 unsafe { Gesture::from_glib_full(ffi::gtk_gesture_rotate_new()).unsafe_cast() }
112 }
113
114 // rustdoc-stripper-ignore-next
115 /// Creates a new builder-pattern struct instance to construct [`GestureRotate`] objects.
116 ///
117 /// This method returns an instance of [`GestureRotateBuilder`](crate::builders::GestureRotateBuilder) which can be used to create [`GestureRotate`] objects.
118 pub fn builder() -> GestureRotateBuilder {
119 GestureRotateBuilder::new()
120 }
121
122 /// Gets the angle delta in radians.
123 ///
124 /// If @self is active, this function returns the angle difference
125 /// in radians since the gesture was first recognized. If @self is
126 /// not active, 0 is returned.
127 ///
128 /// # Returns
129 ///
130 /// the angle delta in radians
131 #[doc(alias = "gtk_gesture_rotate_get_angle_delta")]
132 #[doc(alias = "get_angle_delta")]
133 pub fn angle_delta(&self) -> f64 {
134 unsafe { ffi::gtk_gesture_rotate_get_angle_delta(self.to_glib_none().0) }
135 }
136
137 /// Emitted when the angle between both tracked points changes.
138 /// ## `angle`
139 /// Current angle in radians
140 /// ## `angle_delta`
141 /// Difference with the starting angle, in radians
142 #[doc(alias = "angle-changed")]
143 pub fn connect_angle_changed<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
144 unsafe extern "C" fn angle_changed_trampoline<F: Fn(&GestureRotate, f64, f64) + 'static>(
145 this: *mut ffi::GtkGestureRotate,
146 angle: std::ffi::c_double,
147 angle_delta: std::ffi::c_double,
148 f: glib::ffi::gpointer,
149 ) {
150 unsafe {
151 let f: &F = &*(f as *const F);
152 f(&from_glib_borrow(this), angle, angle_delta)
153 }
154 }
155 unsafe {
156 let f: Box_<F> = Box_::new(f);
157 connect_raw(
158 self.as_ptr() as *mut _,
159 c"angle-changed".as_ptr() as *const _,
160 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
161 angle_changed_trampoline::<F> as *const (),
162 )),
163 Box_::into_raw(f),
164 )
165 }
166 }
167}
168
169impl Default for GestureRotate {
170 fn default() -> Self {
171 Self::new()
172 }
173}
174
175// rustdoc-stripper-ignore-next
176/// A [builder-pattern] type to construct [`GestureRotate`] objects.
177///
178/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
179#[must_use = "The builder must be built to be used"]
180pub struct GestureRotateBuilder {
181 builder: glib::object::ObjectBuilder<'static, GestureRotate>,
182}
183
184impl GestureRotateBuilder {
185 fn new() -> Self {
186 Self {
187 builder: glib::object::Object::builder(),
188 }
189 }
190
191 /// The number of touch points that trigger
192 /// recognition on this gesture.
193 pub fn n_points(self, n_points: u32) -> Self {
194 Self {
195 builder: self.builder.property("n-points", n_points),
196 }
197 }
198
199 /// The name for this controller, typically used for debugging purposes.
200 pub fn name(self, name: impl Into<glib::GString>) -> Self {
201 Self {
202 builder: self.builder.property("name", name.into()),
203 }
204 }
205
206 /// The limit for which events this controller will handle.
207 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
208 Self {
209 builder: self
210 .builder
211 .property("propagation-limit", propagation_limit),
212 }
213 }
214
215 /// The propagation phase at which this controller will handle events.
216 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
217 Self {
218 builder: self
219 .builder
220 .property("propagation-phase", propagation_phase),
221 }
222 }
223
224 // rustdoc-stripper-ignore-next
225 /// Build the [`GestureRotate`].
226 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
227 pub fn build(self) -> GestureRotate {
228 assert_initialized_main_thread!();
229 self.builder.build()
230 }
231}