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