gtk/auto/
event_controller_motion.rs1use crate::{EventController, 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 #[doc(alias = "enter")]
77 pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
78 unsafe extern "C" fn enter_trampoline<F: Fn(&EventControllerMotion, f64, f64) + 'static>(
79 this: *mut ffi::GtkEventControllerMotion,
80 x: std::ffi::c_double,
81 y: std::ffi::c_double,
82 f: glib::ffi::gpointer,
83 ) {
84 unsafe {
85 let f: &F = &*(f as *const F);
86 f(&from_glib_borrow(this), x, y)
87 }
88 }
89 unsafe {
90 let f: Box_<F> = Box_::new(f);
91 connect_raw(
92 self.as_ptr() as *mut _,
93 c"enter".as_ptr(),
94 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
95 enter_trampoline::<F> as *const (),
96 )),
97 Box_::into_raw(f),
98 )
99 }
100 }
101
102 #[doc(alias = "leave")]
104 pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
105 unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerMotion) + 'static>(
106 this: *mut ffi::GtkEventControllerMotion,
107 f: glib::ffi::gpointer,
108 ) {
109 unsafe {
110 let f: &F = &*(f as *const F);
111 f(&from_glib_borrow(this))
112 }
113 }
114 unsafe {
115 let f: Box_<F> = Box_::new(f);
116 connect_raw(
117 self.as_ptr() as *mut _,
118 c"leave".as_ptr(),
119 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
120 leave_trampoline::<F> as *const (),
121 )),
122 Box_::into_raw(f),
123 )
124 }
125 }
126
127 #[doc(alias = "motion")]
133 pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
134 unsafe extern "C" fn motion_trampoline<
135 F: Fn(&EventControllerMotion, f64, f64) + 'static,
136 >(
137 this: *mut ffi::GtkEventControllerMotion,
138 x: std::ffi::c_double,
139 y: std::ffi::c_double,
140 f: glib::ffi::gpointer,
141 ) {
142 unsafe {
143 let f: &F = &*(f as *const F);
144 f(&from_glib_borrow(this), x, y)
145 }
146 }
147 unsafe {
148 let f: Box_<F> = Box_::new(f);
149 connect_raw(
150 self.as_ptr() as *mut _,
151 c"motion".as_ptr(),
152 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
153 motion_trampoline::<F> as *const (),
154 )),
155 Box_::into_raw(f),
156 )
157 }
158 }
159}