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, 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 /// [`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 // rustdoc-stripper-ignore-next
142 /// Creates a new builder-pattern struct instance to construct [`EventControllerScroll`] objects.
143 ///
144 /// This method returns an instance of [`EventControllerScrollBuilder`](crate::builders::EventControllerScrollBuilder) which can be used to create [`EventControllerScroll`] objects.
145 pub fn builder() -> EventControllerScrollBuilder {
146 EventControllerScrollBuilder::new()
147 }
148
149 /// Gets the flags conditioning the scroll controller behavior.
150 ///
151 /// # Returns
152 ///
153 /// the controller flags.
154 #[doc(alias = "gtk_event_controller_scroll_get_flags")]
155 #[doc(alias = "get_flags")]
156 pub fn flags(&self) -> EventControllerScrollFlags {
157 unsafe {
158 from_glib(ffi::gtk_event_controller_scroll_get_flags(
159 self.to_glib_none().0,
160 ))
161 }
162 }
163
164 /// Sets the flags conditioning scroll controller behavior.
165 /// ## `flags`
166 /// behavior flags
167 #[doc(alias = "gtk_event_controller_scroll_set_flags")]
168 #[doc(alias = "flags")]
169 pub fn set_flags(&self, flags: EventControllerScrollFlags) {
170 unsafe {
171 ffi::gtk_event_controller_scroll_set_flags(self.to_glib_none().0, flags.into_glib());
172 }
173 }
174
175 /// Emitted after scroll is finished if the [`EventControllerScrollFlags::KINETIC`][crate::EventControllerScrollFlags::KINETIC]
176 /// flag is set. `vel_x` and `vel_y` express the initial velocity that was
177 /// imprinted by the scroll events. `vel_x` and `vel_y` are expressed in
178 /// pixels/ms.
179 /// ## `vel_x`
180 /// X velocity
181 /// ## `vel_y`
182 /// Y velocity
183 #[doc(alias = "decelerate")]
184 pub fn connect_decelerate<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
185 unsafe extern "C" fn decelerate_trampoline<
186 F: Fn(&EventControllerScroll, f64, f64) + 'static,
187 >(
188 this: *mut ffi::GtkEventControllerScroll,
189 vel_x: std::ffi::c_double,
190 vel_y: std::ffi::c_double,
191 f: glib::ffi::gpointer,
192 ) {
193 unsafe {
194 let f: &F = &*(f as *const F);
195 f(&from_glib_borrow(this), vel_x, vel_y)
196 }
197 }
198 unsafe {
199 let f: Box_<F> = Box_::new(f);
200 connect_raw(
201 self.as_ptr() as *mut _,
202 c"decelerate".as_ptr(),
203 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
204 decelerate_trampoline::<F> as *const (),
205 )),
206 Box_::into_raw(f),
207 )
208 }
209 }
210
211 /// Signals that the widget should scroll by the
212 /// amount specified by `dx` and `dy`.
213 /// ## `dx`
214 /// X delta
215 /// ## `dy`
216 /// Y delta
217 #[doc(alias = "scroll")]
218 pub fn connect_scroll<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
219 unsafe extern "C" fn scroll_trampoline<
220 F: Fn(&EventControllerScroll, f64, f64) + 'static,
221 >(
222 this: *mut ffi::GtkEventControllerScroll,
223 dx: std::ffi::c_double,
224 dy: std::ffi::c_double,
225 f: glib::ffi::gpointer,
226 ) {
227 unsafe {
228 let f: &F = &*(f as *const F);
229 f(&from_glib_borrow(this), dx, dy)
230 }
231 }
232 unsafe {
233 let f: Box_<F> = Box_::new(f);
234 connect_raw(
235 self.as_ptr() as *mut _,
236 c"scroll".as_ptr(),
237 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
238 scroll_trampoline::<F> as *const (),
239 )),
240 Box_::into_raw(f),
241 )
242 }
243 }
244
245 /// Signals that a new scrolling operation has begun. It will
246 /// only be emitted on devices capable of it.
247 #[doc(alias = "scroll-begin")]
248 pub fn connect_scroll_begin<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
249 unsafe extern "C" fn scroll_begin_trampoline<F: Fn(&EventControllerScroll) + 'static>(
250 this: *mut ffi::GtkEventControllerScroll,
251 f: glib::ffi::gpointer,
252 ) {
253 unsafe {
254 let f: &F = &*(f as *const F);
255 f(&from_glib_borrow(this))
256 }
257 }
258 unsafe {
259 let f: Box_<F> = Box_::new(f);
260 connect_raw(
261 self.as_ptr() as *mut _,
262 c"scroll-begin".as_ptr(),
263 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
264 scroll_begin_trampoline::<F> as *const (),
265 )),
266 Box_::into_raw(f),
267 )
268 }
269 }
270
271 /// Signals that a new scrolling operation has finished. It will
272 /// only be emitted on devices capable of it.
273 #[doc(alias = "scroll-end")]
274 pub fn connect_scroll_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
275 unsafe extern "C" fn scroll_end_trampoline<F: Fn(&EventControllerScroll) + 'static>(
276 this: *mut ffi::GtkEventControllerScroll,
277 f: glib::ffi::gpointer,
278 ) {
279 unsafe {
280 let f: &F = &*(f as *const F);
281 f(&from_glib_borrow(this))
282 }
283 }
284 unsafe {
285 let f: Box_<F> = Box_::new(f);
286 connect_raw(
287 self.as_ptr() as *mut _,
288 c"scroll-end".as_ptr(),
289 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290 scroll_end_trampoline::<F> as *const (),
291 )),
292 Box_::into_raw(f),
293 )
294 }
295 }
296
297 #[cfg(feature = "v3_24")]
298 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
299 #[doc(alias = "flags")]
300 pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
301 unsafe extern "C" fn notify_flags_trampoline<F: Fn(&EventControllerScroll) + 'static>(
302 this: *mut ffi::GtkEventControllerScroll,
303 _param_spec: glib::ffi::gpointer,
304 f: glib::ffi::gpointer,
305 ) {
306 unsafe {
307 let f: &F = &*(f as *const F);
308 f(&from_glib_borrow(this))
309 }
310 }
311 unsafe {
312 let f: Box_<F> = Box_::new(f);
313 connect_raw(
314 self.as_ptr() as *mut _,
315 c"notify::flags".as_ptr(),
316 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
317 notify_flags_trampoline::<F> as *const (),
318 )),
319 Box_::into_raw(f),
320 )
321 }
322 }
323}
324
325#[cfg(feature = "v3_24")]
326#[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
327impl Default for EventControllerScroll {
328 fn default() -> Self {
329 glib::object::Object::new::<Self>()
330 }
331}
332
333// rustdoc-stripper-ignore-next
334/// A [builder-pattern] type to construct [`EventControllerScroll`] objects.
335///
336/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
337#[must_use = "The builder must be built to be used"]
338pub struct EventControllerScrollBuilder {
339 builder: glib::object::ObjectBuilder<'static, EventControllerScroll>,
340}
341
342impl EventControllerScrollBuilder {
343 fn new() -> Self {
344 Self {
345 builder: glib::object::Object::builder(),
346 }
347 }
348
349 /// The flags affecting event controller behavior
350 #[cfg(feature = "v3_24")]
351 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
352 pub fn flags(self, flags: EventControllerScrollFlags) -> Self {
353 Self {
354 builder: self.builder.property("flags", flags),
355 }
356 }
357
358 /// The propagation phase at which this controller will handle events.
359 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
360 Self {
361 builder: self
362 .builder
363 .property("propagation-phase", propagation_phase),
364 }
365 }
366
367 /// The widget receiving the `GdkEvents` that the controller will handle.
368 pub fn widget(self, widget: &impl IsA<Widget>) -> Self {
369 Self {
370 builder: self.builder.property("widget", widget.clone().upcast()),
371 }
372 }
373
374 // rustdoc-stripper-ignore-next
375 /// Build the [`EventControllerScroll`].
376 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
377 pub fn build(self) -> EventControllerScroll {
378 assert_initialized_main_thread!();
379 self.builder.build()
380 }
381}