Skip to main content

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