Skip to main content

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};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14    /// [`GestureZoom`][crate::GestureZoom] is a [`Gesture`][crate::Gesture] implementation able to recognize
15    /// pinch/zoom gestures, whenever the distance between both tracked
16    /// sequences changes, the [`scale-changed`][struct@crate::GestureZoom#scale-changed] signal is
17    /// emitted to report the scale factor.
18    ///
19    /// ## Signals
20    ///
21    ///
22    /// #### `scale-changed`
23    ///  This signal is emitted whenever the distance between both tracked
24    /// sequences 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 = "GtkGestureZoom")]
86    pub struct GestureZoom(Object<ffi::GtkGestureZoom, ffi::GtkGestureZoomClass>) @extends Gesture, EventController;
87
88    match fn {
89        type_ => || ffi::gtk_gesture_zoom_get_type(),
90    }
91}
92
93impl GestureZoom {
94    /// Returns a newly created [`Gesture`][crate::Gesture] that recognizes zoom
95    /// in/out gestures (usually known as pinch/zoom).
96    /// ## `widget`
97    /// a [`Widget`][crate::Widget]
98    ///
99    /// # Returns
100    ///
101    /// a newly created [`GestureZoom`][crate::GestureZoom]
102    #[doc(alias = "gtk_gesture_zoom_new")]
103    pub fn new(widget: &impl IsA<Widget>) -> GestureZoom {
104        skip_assert_initialized!();
105        unsafe {
106            Gesture::from_glib_full(ffi::gtk_gesture_zoom_new(widget.as_ref().to_glib_none().0))
107                .unsafe_cast()
108        }
109    }
110
111    // rustdoc-stripper-ignore-next
112    /// Creates a new builder-pattern struct instance to construct [`GestureZoom`] objects.
113    ///
114    /// This method returns an instance of [`GestureZoomBuilder`](crate::builders::GestureZoomBuilder) which can be used to create [`GestureZoom`] objects.
115    pub fn builder() -> GestureZoomBuilder {
116        GestureZoomBuilder::new()
117    }
118
119    /// If `self` is active, this function returns the zooming difference
120    /// since the gesture was recognized (hence the starting point is
121    /// considered 1:1). If `self` is not active, 1 is returned.
122    ///
123    /// # Returns
124    ///
125    /// the scale delta
126    #[doc(alias = "gtk_gesture_zoom_get_scale_delta")]
127    #[doc(alias = "get_scale_delta")]
128    pub fn scale_delta(&self) -> f64 {
129        unsafe { ffi::gtk_gesture_zoom_get_scale_delta(self.to_glib_none().0) }
130    }
131
132    /// This signal is emitted whenever the distance between both tracked
133    /// sequences changes.
134    /// ## `scale`
135    /// Scale delta, taking the initial state as 1:1
136    #[doc(alias = "scale-changed")]
137    pub fn connect_scale_changed<F: Fn(&Self, f64) + 'static>(&self, f: F) -> SignalHandlerId {
138        unsafe extern "C" fn scale_changed_trampoline<F: Fn(&GestureZoom, f64) + 'static>(
139            this: *mut ffi::GtkGestureZoom,
140            scale: libc::c_double,
141            f: glib::ffi::gpointer,
142        ) {
143            let f: &F = &*(f as *const F);
144            f(&from_glib_borrow(this), scale)
145        }
146        unsafe {
147            let f: Box_<F> = Box_::new(f);
148            connect_raw(
149                self.as_ptr() as *mut _,
150                b"scale-changed\0".as_ptr() as *const _,
151                Some(transmute::<_, unsafe extern "C" fn()>(
152                    scale_changed_trampoline::<F> as *const (),
153                )),
154                Box_::into_raw(f),
155            )
156        }
157    }
158}
159
160impl Default for GestureZoom {
161    fn default() -> Self {
162        glib::object::Object::new::<Self>()
163    }
164}
165
166// rustdoc-stripper-ignore-next
167/// A [builder-pattern] type to construct [`GestureZoom`] objects.
168///
169/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
170#[must_use = "The builder must be built to be used"]
171pub struct GestureZoomBuilder {
172    builder: glib::object::ObjectBuilder<'static, GestureZoom>,
173}
174
175impl GestureZoomBuilder {
176    fn new() -> Self {
177        Self {
178            builder: glib::object::Object::builder(),
179        }
180    }
181
182    /// The number of touch points that trigger recognition on this gesture,
183    pub fn n_points(self, n_points: u32) -> Self {
184        Self {
185            builder: self.builder.property("n-points", n_points),
186        }
187    }
188
189    /// If non-[`None`], the gesture will only listen for events that happen on
190    /// this [`gdk::Window`][crate::gdk::Window], or a child of it.
191    pub fn window(self, window: &gdk::Window) -> Self {
192        Self {
193            builder: self.builder.property("window", window.clone()),
194        }
195    }
196
197    /// The propagation phase at which this controller will handle events.
198    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
199        Self {
200            builder: self
201                .builder
202                .property("propagation-phase", propagation_phase),
203        }
204    }
205
206    /// The widget receiving the `GdkEvents` that the controller will handle.
207    pub fn widget(self, widget: &impl IsA<Widget>) -> Self {
208        Self {
209            builder: self.builder.property("widget", widget.clone().upcast()),
210        }
211    }
212
213    // rustdoc-stripper-ignore-next
214    /// Build the [`GestureZoom`].
215    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
216    pub fn build(self) -> GestureZoom {
217        self.builder.build()
218    }
219}
220
221impl fmt::Display for GestureZoom {
222    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
223        f.write_str("GestureZoom")
224    }
225}