gtk/auto/
event_controller_motion.rs1use crate::{EventController, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 #[doc(alias = "GtkEventControllerMotion")]
43 pub struct EventControllerMotion(Object<ffi::GtkEventControllerMotion, ffi::GtkEventControllerMotionClass>) @extends EventController;
44
45 match fn {
46 type_ => || ffi::gtk_event_controller_motion_get_type(),
47 }
48}
49
50impl EventControllerMotion {
51 #[doc(alias = "gtk_event_controller_motion_new")]
60 pub fn new(widget: &impl IsA<Widget>) -> EventControllerMotion {
61 skip_assert_initialized!();
62 unsafe {
63 EventController::from_glib_full(ffi::gtk_event_controller_motion_new(
64 widget.as_ref().to_glib_none().0,
65 ))
66 .unsafe_cast()
67 }
68 }
69
70 #[doc(alias = "enter")]
76 pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
77 unsafe extern "C" fn enter_trampoline<F: Fn(&EventControllerMotion, f64, f64) + 'static>(
78 this: *mut ffi::GtkEventControllerMotion,
79 x: libc::c_double,
80 y: libc::c_double,
81 f: glib::ffi::gpointer,
82 ) {
83 let f: &F = &*(f as *const F);
84 f(&from_glib_borrow(this), x, y)
85 }
86 unsafe {
87 let f: Box_<F> = Box_::new(f);
88 connect_raw(
89 self.as_ptr() as *mut _,
90 b"enter\0".as_ptr() as *const _,
91 Some(transmute::<_, unsafe extern "C" fn()>(
92 enter_trampoline::<F> as *const (),
93 )),
94 Box_::into_raw(f),
95 )
96 }
97 }
98
99 #[doc(alias = "leave")]
101 pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
102 unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerMotion) + 'static>(
103 this: *mut ffi::GtkEventControllerMotion,
104 f: glib::ffi::gpointer,
105 ) {
106 let f: &F = &*(f as *const F);
107 f(&from_glib_borrow(this))
108 }
109 unsafe {
110 let f: Box_<F> = Box_::new(f);
111 connect_raw(
112 self.as_ptr() as *mut _,
113 b"leave\0".as_ptr() as *const _,
114 Some(transmute::<_, unsafe extern "C" fn()>(
115 leave_trampoline::<F> as *const (),
116 )),
117 Box_::into_raw(f),
118 )
119 }
120 }
121
122 #[doc(alias = "motion")]
128 pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
129 unsafe extern "C" fn motion_trampoline<
130 F: Fn(&EventControllerMotion, f64, f64) + 'static,
131 >(
132 this: *mut ffi::GtkEventControllerMotion,
133 x: libc::c_double,
134 y: libc::c_double,
135 f: glib::ffi::gpointer,
136 ) {
137 let f: &F = &*(f as *const F);
138 f(&from_glib_borrow(this), x, y)
139 }
140 unsafe {
141 let f: Box_<F> = Box_::new(f);
142 connect_raw(
143 self.as_ptr() as *mut _,
144 b"motion\0".as_ptr() as *const _,
145 Some(transmute::<_, unsafe extern "C" fn()>(
146 motion_trampoline::<F> as *const (),
147 )),
148 Box_::into_raw(f),
149 )
150 }
151 }
152}
153
154impl fmt::Display for EventControllerMotion {
155 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
156 f.write_str("EventControllerMotion")
157 }
158}