[go: up one dir, main page]

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    #[doc(alias = "GtkGestureZoom")]
16    pub struct GestureZoom(Object<ffi::GtkGestureZoom, ffi::GtkGestureZoomClass>) @extends Gesture, EventController;
17
18    match fn {
19        type_ => || ffi::gtk_gesture_zoom_get_type(),
20    }
21}
22
23impl GestureZoom {
24    #[doc(alias = "gtk_gesture_zoom_new")]
25    pub fn new() -> GestureZoom {
26        assert_initialized_main_thread!();
27        unsafe { Gesture::from_glib_full(ffi::gtk_gesture_zoom_new()).unsafe_cast() }
28    }
29
30    // rustdoc-stripper-ignore-next
31    /// Creates a new builder-pattern struct instance to construct [`GestureZoom`] objects.
32    ///
33    /// This method returns an instance of [`GestureZoomBuilder`](crate::builders::GestureZoomBuilder) which can be used to create [`GestureZoom`] objects.
34    pub fn builder() -> GestureZoomBuilder {
35        GestureZoomBuilder::new()
36    }
37
38    #[doc(alias = "gtk_gesture_zoom_get_scale_delta")]
39    #[doc(alias = "get_scale_delta")]
40    pub fn scale_delta(&self) -> f64 {
41        unsafe { ffi::gtk_gesture_zoom_get_scale_delta(self.to_glib_none().0) }
42    }
43
44    #[doc(alias = "scale-changed")]
45    pub fn connect_scale_changed<F: Fn(&Self, f64) + 'static>(&self, f: F) -> SignalHandlerId {
46        unsafe extern "C" fn scale_changed_trampoline<F: Fn(&GestureZoom, f64) + 'static>(
47            this: *mut ffi::GtkGestureZoom,
48            scale: std::ffi::c_double,
49            f: glib::ffi::gpointer,
50        ) {
51            let f: &F = &*(f as *const F);
52            f(&from_glib_borrow(this), scale)
53        }
54        unsafe {
55            let f: Box_<F> = Box_::new(f);
56            connect_raw(
57                self.as_ptr() as *mut _,
58                c"scale-changed".as_ptr() as *const _,
59                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
60                    scale_changed_trampoline::<F> as *const (),
61                )),
62                Box_::into_raw(f),
63            )
64        }
65    }
66}
67
68impl Default for GestureZoom {
69    fn default() -> Self {
70        Self::new()
71    }
72}
73
74// rustdoc-stripper-ignore-next
75/// A [builder-pattern] type to construct [`GestureZoom`] objects.
76///
77/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
78#[must_use = "The builder must be built to be used"]
79pub struct GestureZoomBuilder {
80    builder: glib::object::ObjectBuilder<'static, GestureZoom>,
81}
82
83impl GestureZoomBuilder {
84    fn new() -> Self {
85        Self {
86            builder: glib::object::Object::builder(),
87        }
88    }
89
90    pub fn n_points(self, n_points: u32) -> Self {
91        Self {
92            builder: self.builder.property("n-points", n_points),
93        }
94    }
95
96    pub fn name(self, name: impl Into<glib::GString>) -> Self {
97        Self {
98            builder: self.builder.property("name", name.into()),
99        }
100    }
101
102    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
103        Self {
104            builder: self
105                .builder
106                .property("propagation-limit", propagation_limit),
107        }
108    }
109
110    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
111        Self {
112            builder: self
113                .builder
114                .property("propagation-phase", propagation_phase),
115        }
116    }
117
118    // rustdoc-stripper-ignore-next
119    /// Build the [`GestureZoom`].
120    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
121    pub fn build(self) -> GestureZoom {
122        assert_initialized_main_thread!();
123        self.builder.build()
124    }
125}