gtk/auto/event_controller_scroll.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::{EventController, EventControllerScrollFlags, 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 /// [`EventControllerScroll`][crate::EventControllerScroll] is an event controller meant to handle
16 /// scroll events from mice and touchpads. It is capable of handling
17 /// both discrete and continuous scroll events, abstracting them both
18 /// on the [`scroll`][struct@crate::EventControllerScroll#scroll] signal (deltas in the
19 /// discrete case are multiples of 1).
20 ///
21 /// In the case of continuous scroll events, [`EventControllerScroll`][crate::EventControllerScroll]
22 /// encloses all [`scroll`][struct@crate::EventControllerScroll#scroll] events between two
23 /// [`scroll-begin`][struct@crate::EventControllerScroll#scroll-begin] and [`scroll-end`][struct@crate::EventControllerScroll#scroll-end]
24 /// signals.
25 ///
26 /// The behavior of the event controller can be modified by the
27 /// flags given at creation time, or modified at a later point through
28 /// [`set_flags()`][Self::set_flags()] (e.g. because the scrolling
29 /// conditions of the widget changed).
30 ///
31 /// The controller can be set up to emit motion for either/both vertical
32 /// and horizontal scroll events through [`EventControllerScrollFlags::VERTICAL`][crate::EventControllerScrollFlags::VERTICAL],
33 /// [`EventControllerScrollFlags::HORIZONTAL`][crate::EventControllerScrollFlags::HORIZONTAL] and `GTK_EVENT_CONTROLLER_SCROLL_BOTH`.
34 /// If any axis is disabled, the respective [`scroll`][struct@crate::EventControllerScroll#scroll]
35 /// delta will be 0. Vertical scroll events will be translated to horizontal
36 /// motion for the devices incapable of horizontal scrolling.
37 ///
38 /// The event controller can also be forced to emit discrete events on all devices
39 /// through [`EventControllerScrollFlags::DISCRETE`][crate::EventControllerScrollFlags::DISCRETE]. This can be used to implement
40 /// discrete actions triggered through scroll events (e.g. switching across
41 /// combobox options).
42 ///
43 /// The [`EventControllerScrollFlags::KINETIC`][crate::EventControllerScrollFlags::KINETIC] flag toggles the emission of the
44 /// [`decelerate`][struct@crate::EventControllerScroll#decelerate] signal, emitted at the end of scrolling
45 /// with two X/Y velocity arguments that are consistent with the motion that
46 /// was received.
47 ///
48 /// This object was added in 3.24.
49 ///
50 /// ## Properties
51 ///
52 ///
53 /// #### `flags`
54 /// The flags affecting event controller behavior
55 ///
56 /// Readable | Writable
57 /// <details><summary><h4>EventController</h4></summary>
58 ///
59 ///
60 /// #### `propagation-phase`
61 /// The propagation phase at which this controller will handle events.
62 ///
63 /// Readable | Writable
64 ///
65 ///
66 /// #### `widget`
67 /// The widget receiving the `GdkEvents` that the controller will handle.
68 ///
69 /// Readable | Writable | Construct Only
70 /// </details>
71 ///
72 /// ## Signals
73 ///
74 ///
75 /// #### `decelerate`
76 /// Emitted after scroll is finished if the [`EventControllerScrollFlags::KINETIC`][crate::EventControllerScrollFlags::KINETIC]
77 /// flag is set. `vel_x` and `vel_y` express the initial velocity that was
78 /// imprinted by the scroll events. `vel_x` and `vel_y` are expressed in
79 /// pixels/ms.
80 ///
81 ///
82 ///
83 ///
84 /// #### `scroll`
85 /// Signals that the widget should scroll by the
86 /// amount specified by `dx` and `dy`.
87 ///
88 ///
89 ///
90 ///
91 /// #### `scroll-begin`
92 /// Signals that a new scrolling operation has begun. It will
93 /// only be emitted on devices capable of it.
94 ///
95 ///
96 ///
97 ///
98 /// #### `scroll-end`
99 /// Signals that a new scrolling operation has finished. It will
100 /// only be emitted on devices capable of it.
101 ///
102 ///
103 ///
104 /// # Implements
105 ///
106 /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
107 #[doc(alias = "GtkEventControllerScroll")]
108 pub struct EventControllerScroll(Object<ffi::GtkEventControllerScroll, ffi::GtkEventControllerScrollClass>) @extends EventController;
109
110 match fn {
111 type_ => || ffi::gtk_event_controller_scroll_get_type(),
112 }
113}
114
115impl EventControllerScroll {
116 /// Creates a new event controller that will handle scroll events
117 /// for the given `widget`.
118 /// ## `widget`
119 /// a [`Widget`][crate::Widget]
120 /// ## `flags`
121 /// behavior flags
122 ///
123 /// # Returns
124 ///
125 /// a new [`EventControllerScroll`][crate::EventControllerScroll]
126 #[doc(alias = "gtk_event_controller_scroll_new")]
127 pub fn new(
128 widget: &impl IsA<Widget>,
129 flags: EventControllerScrollFlags,
130 ) -> EventControllerScroll {
131 skip_assert_initialized!();
132 unsafe {
133 EventController::from_glib_full(ffi::gtk_event_controller_scroll_new(
134 widget.as_ref().to_glib_none().0,
135 flags.into_glib(),
136 ))
137 .unsafe_cast()
138 }
139 }
140
141 /// Gets the flags conditioning the scroll controller behavior.
142 ///
143 /// # Returns
144 ///
145 /// the controller flags.
146 #[doc(alias = "gtk_event_controller_scroll_get_flags")]
147 #[doc(alias = "get_flags")]
148 pub fn flags(&self) -> EventControllerScrollFlags {
149 unsafe {
150 from_glib(ffi::gtk_event_controller_scroll_get_flags(
151 self.to_glib_none().0,
152 ))
153 }
154 }
155
156 /// Sets the flags conditioning scroll controller behavior.
157 /// ## `flags`
158 /// behavior flags
159 #[doc(alias = "gtk_event_controller_scroll_set_flags")]
160 #[doc(alias = "flags")]
161 pub fn set_flags(&self, flags: EventControllerScrollFlags) {
162 unsafe {
163 ffi::gtk_event_controller_scroll_set_flags(self.to_glib_none().0, flags.into_glib());
164 }
165 }
166
167 /// Emitted after scroll is finished if the [`EventControllerScrollFlags::KINETIC`][crate::EventControllerScrollFlags::KINETIC]
168 /// flag is set. `vel_x` and `vel_y` express the initial velocity that was
169 /// imprinted by the scroll events. `vel_x` and `vel_y` are expressed in
170 /// pixels/ms.
171 /// ## `vel_x`
172 /// X velocity
173 /// ## `vel_y`
174 /// Y velocity
175 #[doc(alias = "decelerate")]
176 pub fn connect_decelerate<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
177 unsafe extern "C" fn decelerate_trampoline<
178 F: Fn(&EventControllerScroll, f64, f64) + 'static,
179 >(
180 this: *mut ffi::GtkEventControllerScroll,
181 vel_x: std::ffi::c_double,
182 vel_y: std::ffi::c_double,
183 f: glib::ffi::gpointer,
184 ) {
185 unsafe {
186 let f: &F = &*(f as *const F);
187 f(&from_glib_borrow(this), vel_x, vel_y)
188 }
189 }
190 unsafe {
191 let f: Box_<F> = Box_::new(f);
192 connect_raw(
193 self.as_ptr() as *mut _,
194 c"decelerate".as_ptr(),
195 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
196 decelerate_trampoline::<F> as *const (),
197 )),
198 Box_::into_raw(f),
199 )
200 }
201 }
202
203 /// Signals that the widget should scroll by the
204 /// amount specified by `dx` and `dy`.
205 /// ## `dx`
206 /// X delta
207 /// ## `dy`
208 /// Y delta
209 #[doc(alias = "scroll")]
210 pub fn connect_scroll<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
211 unsafe extern "C" fn scroll_trampoline<
212 F: Fn(&EventControllerScroll, f64, f64) + 'static,
213 >(
214 this: *mut ffi::GtkEventControllerScroll,
215 dx: std::ffi::c_double,
216 dy: std::ffi::c_double,
217 f: glib::ffi::gpointer,
218 ) {
219 unsafe {
220 let f: &F = &*(f as *const F);
221 f(&from_glib_borrow(this), dx, dy)
222 }
223 }
224 unsafe {
225 let f: Box_<F> = Box_::new(f);
226 connect_raw(
227 self.as_ptr() as *mut _,
228 c"scroll".as_ptr(),
229 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
230 scroll_trampoline::<F> as *const (),
231 )),
232 Box_::into_raw(f),
233 )
234 }
235 }
236
237 /// Signals that a new scrolling operation has begun. It will
238 /// only be emitted on devices capable of it.
239 #[doc(alias = "scroll-begin")]
240 pub fn connect_scroll_begin<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
241 unsafe extern "C" fn scroll_begin_trampoline<F: Fn(&EventControllerScroll) + 'static>(
242 this: *mut ffi::GtkEventControllerScroll,
243 f: glib::ffi::gpointer,
244 ) {
245 unsafe {
246 let f: &F = &*(f as *const F);
247 f(&from_glib_borrow(this))
248 }
249 }
250 unsafe {
251 let f: Box_<F> = Box_::new(f);
252 connect_raw(
253 self.as_ptr() as *mut _,
254 c"scroll-begin".as_ptr(),
255 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
256 scroll_begin_trampoline::<F> as *const (),
257 )),
258 Box_::into_raw(f),
259 )
260 }
261 }
262
263 /// Signals that a new scrolling operation has finished. It will
264 /// only be emitted on devices capable of it.
265 #[doc(alias = "scroll-end")]
266 pub fn connect_scroll_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
267 unsafe extern "C" fn scroll_end_trampoline<F: Fn(&EventControllerScroll) + 'static>(
268 this: *mut ffi::GtkEventControllerScroll,
269 f: glib::ffi::gpointer,
270 ) {
271 unsafe {
272 let f: &F = &*(f as *const F);
273 f(&from_glib_borrow(this))
274 }
275 }
276 unsafe {
277 let f: Box_<F> = Box_::new(f);
278 connect_raw(
279 self.as_ptr() as *mut _,
280 c"scroll-end".as_ptr(),
281 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
282 scroll_end_trampoline::<F> as *const (),
283 )),
284 Box_::into_raw(f),
285 )
286 }
287 }
288
289 #[cfg(feature = "v3_24")]
290 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
291 #[doc(alias = "flags")]
292 pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
293 unsafe extern "C" fn notify_flags_trampoline<F: Fn(&EventControllerScroll) + 'static>(
294 this: *mut ffi::GtkEventControllerScroll,
295 _param_spec: glib::ffi::gpointer,
296 f: glib::ffi::gpointer,
297 ) {
298 unsafe {
299 let f: &F = &*(f as *const F);
300 f(&from_glib_borrow(this))
301 }
302 }
303 unsafe {
304 let f: Box_<F> = Box_::new(f);
305 connect_raw(
306 self.as_ptr() as *mut _,
307 c"notify::flags".as_ptr(),
308 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
309 notify_flags_trampoline::<F> as *const (),
310 )),
311 Box_::into_raw(f),
312 )
313 }
314 }
315}