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