[go: up one dir, main page]

gtk4/auto/
gesture_swipe.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, GestureSingle, 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 = "GtkGestureSwipe")]
16    pub struct GestureSwipe(Object<ffi::GtkGestureSwipe, ffi::GtkGestureSwipeClass>) @extends GestureSingle, Gesture, EventController;
17
18    match fn {
19        type_ => || ffi::gtk_gesture_swipe_get_type(),
20    }
21}
22
23impl GestureSwipe {
24    #[doc(alias = "gtk_gesture_swipe_new")]
25    pub fn new() -> GestureSwipe {
26        assert_initialized_main_thread!();
27        unsafe { Gesture::from_glib_full(ffi::gtk_gesture_swipe_new()).unsafe_cast() }
28    }
29
30    // rustdoc-stripper-ignore-next
31    /// Creates a new builder-pattern struct instance to construct [`GestureSwipe`] objects.
32    ///
33    /// This method returns an instance of [`GestureSwipeBuilder`](crate::builders::GestureSwipeBuilder) which can be used to create [`GestureSwipe`] objects.
34    pub fn builder() -> GestureSwipeBuilder {
35        GestureSwipeBuilder::new()
36    }
37
38    #[doc(alias = "gtk_gesture_swipe_get_velocity")]
39    #[doc(alias = "get_velocity")]
40    pub fn velocity(&self) -> Option<(f64, f64)> {
41        unsafe {
42            let mut velocity_x = std::mem::MaybeUninit::uninit();
43            let mut velocity_y = std::mem::MaybeUninit::uninit();
44            let ret = from_glib(ffi::gtk_gesture_swipe_get_velocity(
45                self.to_glib_none().0,
46                velocity_x.as_mut_ptr(),
47                velocity_y.as_mut_ptr(),
48            ));
49            if ret {
50                Some((velocity_x.assume_init(), velocity_y.assume_init()))
51            } else {
52                None
53            }
54        }
55    }
56
57    #[doc(alias = "swipe")]
58    pub fn connect_swipe<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
59        unsafe extern "C" fn swipe_trampoline<F: Fn(&GestureSwipe, f64, f64) + 'static>(
60            this: *mut ffi::GtkGestureSwipe,
61            velocity_x: std::ffi::c_double,
62            velocity_y: std::ffi::c_double,
63            f: glib::ffi::gpointer,
64        ) {
65            let f: &F = &*(f as *const F);
66            f(&from_glib_borrow(this), velocity_x, velocity_y)
67        }
68        unsafe {
69            let f: Box_<F> = Box_::new(f);
70            connect_raw(
71                self.as_ptr() as *mut _,
72                c"swipe".as_ptr() as *const _,
73                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
74                    swipe_trampoline::<F> as *const (),
75                )),
76                Box_::into_raw(f),
77            )
78        }
79    }
80}
81
82impl Default for GestureSwipe {
83    fn default() -> Self {
84        Self::new()
85    }
86}
87
88// rustdoc-stripper-ignore-next
89/// A [builder-pattern] type to construct [`GestureSwipe`] objects.
90///
91/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
92#[must_use = "The builder must be built to be used"]
93pub struct GestureSwipeBuilder {
94    builder: glib::object::ObjectBuilder<'static, GestureSwipe>,
95}
96
97impl GestureSwipeBuilder {
98    fn new() -> Self {
99        Self {
100            builder: glib::object::Object::builder(),
101        }
102    }
103
104    pub fn button(self, button: u32) -> Self {
105        Self {
106            builder: self.builder.property("button", button),
107        }
108    }
109
110    pub fn exclusive(self, exclusive: bool) -> Self {
111        Self {
112            builder: self.builder.property("exclusive", exclusive),
113        }
114    }
115
116    pub fn touch_only(self, touch_only: bool) -> Self {
117        Self {
118            builder: self.builder.property("touch-only", touch_only),
119        }
120    }
121
122    pub fn n_points(self, n_points: u32) -> Self {
123        Self {
124            builder: self.builder.property("n-points", n_points),
125        }
126    }
127
128    pub fn name(self, name: impl Into<glib::GString>) -> Self {
129        Self {
130            builder: self.builder.property("name", name.into()),
131        }
132    }
133
134    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
135        Self {
136            builder: self
137                .builder
138                .property("propagation-limit", propagation_limit),
139        }
140    }
141
142    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
143        Self {
144            builder: self
145                .builder
146                .property("propagation-phase", propagation_phase),
147        }
148    }
149
150    // rustdoc-stripper-ignore-next
151    /// Build the [`GestureSwipe`].
152    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
153    pub fn build(self) -> GestureSwipe {
154        assert_initialized_main_thread!();
155        self.builder.build()
156    }
157}