gtk/auto/
event_controller_motion.rs1use crate::{EventController, PropagationPhase, Widget, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkEventControllerMotion")]
44 pub struct EventControllerMotion(Object<ffi::GtkEventControllerMotion, ffi::GtkEventControllerMotionClass>) @extends EventController;
45
46 match fn {
47 type_ => || ffi::gtk_event_controller_motion_get_type(),
48 }
49}
50
51impl EventControllerMotion {
52 #[doc(alias = "gtk_event_controller_motion_new")]
61 pub fn new(widget: &impl IsA<Widget>) -> EventControllerMotion {
62 skip_assert_initialized!();
63 unsafe {
64 EventController::from_glib_full(ffi::gtk_event_controller_motion_new(
65 widget.as_ref().to_glib_none().0,
66 ))
67 .unsafe_cast()
68 }
69 }
70
71 pub fn builder() -> EventControllerMotionBuilder {
76 EventControllerMotionBuilder::new()
77 }
78
79 #[doc(alias = "enter")]
85 pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
86 unsafe extern "C" fn enter_trampoline<F: Fn(&EventControllerMotion, f64, f64) + 'static>(
87 this: *mut ffi::GtkEventControllerMotion,
88 x: std::ffi::c_double,
89 y: std::ffi::c_double,
90 f: glib::ffi::gpointer,
91 ) {
92 unsafe {
93 let f: &F = &*(f as *const F);
94 f(&from_glib_borrow(this), x, y)
95 }
96 }
97 unsafe {
98 let f: Box_<F> = Box_::new(f);
99 connect_raw(
100 self.as_ptr() as *mut _,
101 c"enter".as_ptr(),
102 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
103 enter_trampoline::<F> as *const (),
104 )),
105 Box_::into_raw(f),
106 )
107 }
108 }
109
110 #[doc(alias = "leave")]
112 pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
113 unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerMotion) + 'static>(
114 this: *mut ffi::GtkEventControllerMotion,
115 f: glib::ffi::gpointer,
116 ) {
117 unsafe {
118 let f: &F = &*(f as *const F);
119 f(&from_glib_borrow(this))
120 }
121 }
122 unsafe {
123 let f: Box_<F> = Box_::new(f);
124 connect_raw(
125 self.as_ptr() as *mut _,
126 c"leave".as_ptr(),
127 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
128 leave_trampoline::<F> as *const (),
129 )),
130 Box_::into_raw(f),
131 )
132 }
133 }
134
135 #[doc(alias = "motion")]
141 pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
142 unsafe extern "C" fn motion_trampoline<
143 F: Fn(&EventControllerMotion, f64, f64) + 'static,
144 >(
145 this: *mut ffi::GtkEventControllerMotion,
146 x: std::ffi::c_double,
147 y: std::ffi::c_double,
148 f: glib::ffi::gpointer,
149 ) {
150 unsafe {
151 let f: &F = &*(f as *const F);
152 f(&from_glib_borrow(this), x, y)
153 }
154 }
155 unsafe {
156 let f: Box_<F> = Box_::new(f);
157 connect_raw(
158 self.as_ptr() as *mut _,
159 c"motion".as_ptr(),
160 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
161 motion_trampoline::<F> as *const (),
162 )),
163 Box_::into_raw(f),
164 )
165 }
166 }
167}
168
169#[cfg(feature = "v3_24")]
170#[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
171impl Default for EventControllerMotion {
172 fn default() -> Self {
173 glib::object::Object::new::<Self>()
174 }
175}
176
177#[must_use = "The builder must be built to be used"]
182pub struct EventControllerMotionBuilder {
183 builder: glib::object::ObjectBuilder<'static, EventControllerMotion>,
184}
185
186impl EventControllerMotionBuilder {
187 fn new() -> Self {
188 Self {
189 builder: glib::object::Object::builder(),
190 }
191 }
192
193 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
195 Self {
196 builder: self
197 .builder
198 .property("propagation-phase", propagation_phase),
199 }
200 }
201
202 pub fn widget(self, widget: &impl IsA<Widget>) -> Self {
204 Self {
205 builder: self.builder.property("widget", widget.clone().upcast()),
206 }
207 }
208
209 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
212 pub fn build(self) -> EventControllerMotion {
213 assert_initialized_main_thread!();
214 self.builder.build()
215 }
216}