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::{ffi, EventController, Gesture, PropagationLimit, PropagationPhase};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// [`GestureRotate`][crate::GestureRotate] is a [`Gesture`][crate::Gesture] for 2-finger rotations.
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`]
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            let f: &F = &*(f as *const F);
151            f(&from_glib_borrow(this), angle, angle_delta)
152        }
153        unsafe {
154            let f: Box_<F> = Box_::new(f);
155            connect_raw(
156                self.as_ptr() as *mut _,
157                b"angle-changed\0".as_ptr() as *const _,
158                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
159                    angle_changed_trampoline::<F> as *const (),
160                )),
161                Box_::into_raw(f),
162            )
163        }
164    }
165}
166
167impl Default for GestureRotate {
168    fn default() -> Self {
169        Self::new()
170    }
171}
172
173// rustdoc-stripper-ignore-next
174/// A [builder-pattern] type to construct [`GestureRotate`] objects.
175///
176/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
177#[must_use = "The builder must be built to be used"]
178pub struct GestureRotateBuilder {
179    builder: glib::object::ObjectBuilder<'static, GestureRotate>,
180}
181
182impl GestureRotateBuilder {
183    fn new() -> Self {
184        Self {
185            builder: glib::object::Object::builder(),
186        }
187    }
188
189    /// The number of touch points that trigger
190    /// recognition on this gesture.
191    pub fn n_points(self, n_points: u32) -> Self {
192        Self {
193            builder: self.builder.property("n-points", n_points),
194        }
195    }
196
197    /// The name for this controller, typically used for debugging purposes.
198    pub fn name(self, name: impl Into<glib::GString>) -> Self {
199        Self {
200            builder: self.builder.property("name", name.into()),
201        }
202    }
203
204    /// The limit for which events this controller will handle.
205    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
206        Self {
207            builder: self
208                .builder
209                .property("propagation-limit", propagation_limit),
210        }
211    }
212
213    /// The propagation phase at which this controller will handle events.
214    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
215        Self {
216            builder: self
217                .builder
218                .property("propagation-phase", propagation_phase),
219        }
220    }
221
222    // rustdoc-stripper-ignore-next
223    /// Build the [`GestureRotate`].
224    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
225    pub fn build(self) -> GestureRotate {
226        assert_initialized_main_thread!();
227        self.builder.build()
228    }
229}