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