[go: up one dir, main page]

gtk4/auto/
gesture_pan.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::{
6    ffi, EventController, Gesture, GestureDrag, GestureSingle, Orientation, PanDirection,
7    PropagationLimit, PropagationPhase,
8};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{connect_raw, SignalHandlerId},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    #[doc(alias = "GtkGesturePan")]
19    pub struct GesturePan(Object<ffi::GtkGesturePan, ffi::GtkGesturePanClass>) @extends GestureDrag, GestureSingle, Gesture, EventController;
20
21    match fn {
22        type_ => || ffi::gtk_gesture_pan_get_type(),
23    }
24}
25
26impl GesturePan {
27    #[doc(alias = "gtk_gesture_pan_new")]
28    pub fn new(orientation: Orientation) -> GesturePan {
29        assert_initialized_main_thread!();
30        unsafe {
31            Gesture::from_glib_full(ffi::gtk_gesture_pan_new(orientation.into_glib())).unsafe_cast()
32        }
33    }
34
35    // rustdoc-stripper-ignore-next
36    /// Creates a new builder-pattern struct instance to construct [`GesturePan`] objects.
37    ///
38    /// This method returns an instance of [`GesturePanBuilder`](crate::builders::GesturePanBuilder) which can be used to create [`GesturePan`] objects.
39    pub fn builder() -> GesturePanBuilder {
40        GesturePanBuilder::new()
41    }
42
43    #[doc(alias = "gtk_gesture_pan_get_orientation")]
44    #[doc(alias = "get_orientation")]
45    pub fn orientation(&self) -> Orientation {
46        unsafe { from_glib(ffi::gtk_gesture_pan_get_orientation(self.to_glib_none().0)) }
47    }
48
49    #[doc(alias = "gtk_gesture_pan_set_orientation")]
50    #[doc(alias = "orientation")]
51    pub fn set_orientation(&self, orientation: Orientation) {
52        unsafe {
53            ffi::gtk_gesture_pan_set_orientation(self.to_glib_none().0, orientation.into_glib());
54        }
55    }
56
57    #[doc(alias = "pan")]
58    pub fn connect_pan<F: Fn(&Self, PanDirection, f64) + 'static>(&self, f: F) -> SignalHandlerId {
59        unsafe extern "C" fn pan_trampoline<F: Fn(&GesturePan, PanDirection, f64) + 'static>(
60            this: *mut ffi::GtkGesturePan,
61            direction: ffi::GtkPanDirection,
62            offset: std::ffi::c_double,
63            f: glib::ffi::gpointer,
64        ) {
65            let f: &F = &*(f as *const F);
66            f(&from_glib_borrow(this), from_glib(direction), offset)
67        }
68        unsafe {
69            let f: Box_<F> = Box_::new(f);
70            connect_raw(
71                self.as_ptr() as *mut _,
72                c"pan".as_ptr() as *const _,
73                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
74                    pan_trampoline::<F> as *const (),
75                )),
76                Box_::into_raw(f),
77            )
78        }
79    }
80
81    #[doc(alias = "orientation")]
82    pub fn connect_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
83        unsafe extern "C" fn notify_orientation_trampoline<F: Fn(&GesturePan) + 'static>(
84            this: *mut ffi::GtkGesturePan,
85            _param_spec: glib::ffi::gpointer,
86            f: glib::ffi::gpointer,
87        ) {
88            let f: &F = &*(f as *const F);
89            f(&from_glib_borrow(this))
90        }
91        unsafe {
92            let f: Box_<F> = Box_::new(f);
93            connect_raw(
94                self.as_ptr() as *mut _,
95                c"notify::orientation".as_ptr() as *const _,
96                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
97                    notify_orientation_trampoline::<F> as *const (),
98                )),
99                Box_::into_raw(f),
100            )
101        }
102    }
103}
104
105impl Default for GesturePan {
106    fn default() -> Self {
107        glib::object::Object::new::<Self>()
108    }
109}
110
111// rustdoc-stripper-ignore-next
112/// A [builder-pattern] type to construct [`GesturePan`] objects.
113///
114/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
115#[must_use = "The builder must be built to be used"]
116pub struct GesturePanBuilder {
117    builder: glib::object::ObjectBuilder<'static, GesturePan>,
118}
119
120impl GesturePanBuilder {
121    fn new() -> Self {
122        Self {
123            builder: glib::object::Object::builder(),
124        }
125    }
126
127    pub fn orientation(self, orientation: Orientation) -> Self {
128        Self {
129            builder: self.builder.property("orientation", orientation),
130        }
131    }
132
133    pub fn button(self, button: u32) -> Self {
134        Self {
135            builder: self.builder.property("button", button),
136        }
137    }
138
139    pub fn exclusive(self, exclusive: bool) -> Self {
140        Self {
141            builder: self.builder.property("exclusive", exclusive),
142        }
143    }
144
145    pub fn touch_only(self, touch_only: bool) -> Self {
146        Self {
147            builder: self.builder.property("touch-only", touch_only),
148        }
149    }
150
151    pub fn n_points(self, n_points: u32) -> Self {
152        Self {
153            builder: self.builder.property("n-points", n_points),
154        }
155    }
156
157    pub fn name(self, name: impl Into<glib::GString>) -> Self {
158        Self {
159            builder: self.builder.property("name", name.into()),
160        }
161    }
162
163    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
164        Self {
165            builder: self
166                .builder
167                .property("propagation-limit", propagation_limit),
168        }
169    }
170
171    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
172        Self {
173            builder: self
174                .builder
175                .property("propagation-phase", propagation_phase),
176        }
177    }
178
179    // rustdoc-stripper-ignore-next
180    /// Build the [`GesturePan`].
181    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
182    pub fn build(self) -> GesturePan {
183        assert_initialized_main_thread!();
184        self.builder.build()
185    }
186}