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