Skip to main content

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