gtk4/auto/
event_controller_motion.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, 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 = "GtkEventControllerMotion")]
16    pub struct EventControllerMotion(Object<ffi::GtkEventControllerMotion, ffi::GtkEventControllerMotionClass>) @extends EventController;
17
18    match fn {
19        type_ => || ffi::gtk_event_controller_motion_get_type(),
20    }
21}
22
23impl EventControllerMotion {
24    #[doc(alias = "gtk_event_controller_motion_new")]
25    pub fn new() -> EventControllerMotion {
26        assert_initialized_main_thread!();
27        unsafe {
28            EventController::from_glib_full(ffi::gtk_event_controller_motion_new()).unsafe_cast()
29        }
30    }
31
32    // rustdoc-stripper-ignore-next
33    /// Creates a new builder-pattern struct instance to construct [`EventControllerMotion`] objects.
34    ///
35    /// This method returns an instance of [`EventControllerMotionBuilder`](crate::builders::EventControllerMotionBuilder) which can be used to create [`EventControllerMotion`] objects.
36    pub fn builder() -> EventControllerMotionBuilder {
37        EventControllerMotionBuilder::new()
38    }
39
40    #[doc(alias = "gtk_event_controller_motion_contains_pointer")]
41    #[doc(alias = "contains-pointer")]
42    pub fn contains_pointer(&self) -> bool {
43        unsafe {
44            from_glib(ffi::gtk_event_controller_motion_contains_pointer(
45                self.to_glib_none().0,
46            ))
47        }
48    }
49
50    #[doc(alias = "gtk_event_controller_motion_is_pointer")]
51    #[doc(alias = "is-pointer")]
52    pub fn is_pointer(&self) -> bool {
53        unsafe {
54            from_glib(ffi::gtk_event_controller_motion_is_pointer(
55                self.to_glib_none().0,
56            ))
57        }
58    }
59
60    #[doc(alias = "enter")]
61    pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
62        unsafe extern "C" fn enter_trampoline<F: Fn(&EventControllerMotion, f64, f64) + 'static>(
63            this: *mut ffi::GtkEventControllerMotion,
64            x: std::ffi::c_double,
65            y: std::ffi::c_double,
66            f: glib::ffi::gpointer,
67        ) {
68            let f: &F = &*(f as *const F);
69            f(&from_glib_borrow(this), x, y)
70        }
71        unsafe {
72            let f: Box_<F> = Box_::new(f);
73            connect_raw(
74                self.as_ptr() as *mut _,
75                c"enter".as_ptr() as *const _,
76                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
77                    enter_trampoline::<F> as *const (),
78                )),
79                Box_::into_raw(f),
80            )
81        }
82    }
83
84    #[doc(alias = "leave")]
85    pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
86        unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerMotion) + 'static>(
87            this: *mut ffi::GtkEventControllerMotion,
88            f: glib::ffi::gpointer,
89        ) {
90            let f: &F = &*(f as *const F);
91            f(&from_glib_borrow(this))
92        }
93        unsafe {
94            let f: Box_<F> = Box_::new(f);
95            connect_raw(
96                self.as_ptr() as *mut _,
97                c"leave".as_ptr() as *const _,
98                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
99                    leave_trampoline::<F> as *const (),
100                )),
101                Box_::into_raw(f),
102            )
103        }
104    }
105
106    #[doc(alias = "motion")]
107    pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
108        unsafe extern "C" fn motion_trampoline<
109            F: Fn(&EventControllerMotion, f64, f64) + 'static,
110        >(
111            this: *mut ffi::GtkEventControllerMotion,
112            x: std::ffi::c_double,
113            y: std::ffi::c_double,
114            f: glib::ffi::gpointer,
115        ) {
116            let f: &F = &*(f as *const F);
117            f(&from_glib_borrow(this), x, y)
118        }
119        unsafe {
120            let f: Box_<F> = Box_::new(f);
121            connect_raw(
122                self.as_ptr() as *mut _,
123                c"motion".as_ptr() as *const _,
124                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
125                    motion_trampoline::<F> as *const (),
126                )),
127                Box_::into_raw(f),
128            )
129        }
130    }
131
132    #[doc(alias = "contains-pointer")]
133    pub fn connect_contains_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
134        unsafe extern "C" fn notify_contains_pointer_trampoline<
135            F: Fn(&EventControllerMotion) + 'static,
136        >(
137            this: *mut ffi::GtkEventControllerMotion,
138            _param_spec: glib::ffi::gpointer,
139            f: glib::ffi::gpointer,
140        ) {
141            let f: &F = &*(f as *const F);
142            f(&from_glib_borrow(this))
143        }
144        unsafe {
145            let f: Box_<F> = Box_::new(f);
146            connect_raw(
147                self.as_ptr() as *mut _,
148                c"notify::contains-pointer".as_ptr() as *const _,
149                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
150                    notify_contains_pointer_trampoline::<F> as *const (),
151                )),
152                Box_::into_raw(f),
153            )
154        }
155    }
156
157    #[doc(alias = "is-pointer")]
158    pub fn connect_is_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
159        unsafe extern "C" fn notify_is_pointer_trampoline<
160            F: Fn(&EventControllerMotion) + 'static,
161        >(
162            this: *mut ffi::GtkEventControllerMotion,
163            _param_spec: glib::ffi::gpointer,
164            f: glib::ffi::gpointer,
165        ) {
166            let f: &F = &*(f as *const F);
167            f(&from_glib_borrow(this))
168        }
169        unsafe {
170            let f: Box_<F> = Box_::new(f);
171            connect_raw(
172                self.as_ptr() as *mut _,
173                c"notify::is-pointer".as_ptr() as *const _,
174                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
175                    notify_is_pointer_trampoline::<F> as *const (),
176                )),
177                Box_::into_raw(f),
178            )
179        }
180    }
181}
182
183impl Default for EventControllerMotion {
184    fn default() -> Self {
185        Self::new()
186    }
187}
188
189// rustdoc-stripper-ignore-next
190/// A [builder-pattern] type to construct [`EventControllerMotion`] objects.
191///
192/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
193#[must_use = "The builder must be built to be used"]
194pub struct EventControllerMotionBuilder {
195    builder: glib::object::ObjectBuilder<'static, EventControllerMotion>,
196}
197
198impl EventControllerMotionBuilder {
199    fn new() -> Self {
200        Self {
201            builder: glib::object::Object::builder(),
202        }
203    }
204
205    pub fn name(self, name: impl Into<glib::GString>) -> Self {
206        Self {
207            builder: self.builder.property("name", name.into()),
208        }
209    }
210
211    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
212        Self {
213            builder: self
214                .builder
215                .property("propagation-limit", propagation_limit),
216        }
217    }
218
219    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
220        Self {
221            builder: self
222                .builder
223                .property("propagation-phase", propagation_phase),
224        }
225    }
226
227    // rustdoc-stripper-ignore-next
228    /// Build the [`EventControllerMotion`].
229    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
230    pub fn build(self) -> EventControllerMotion {
231        assert_initialized_main_thread!();
232        self.builder.build()
233    }
234}