gtk4/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::{ffi, EventController, EventControllerScrollFlags, PropagationLimit, PropagationPhase};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// [`EventControllerScroll`][crate::EventControllerScroll] is an event controller that handles scroll
16 /// events.
17 ///
18 /// It is capable of handling both discrete and continuous scroll
19 /// events from mice or touchpads, abstracting them both with the
20 /// [`scroll`][struct@crate::EventControllerScroll#scroll] signal. Deltas in
21 /// the discrete case are multiples of 1.
22 ///
23 /// In the case of continuous scroll events, [`EventControllerScroll`][crate::EventControllerScroll]
24 /// encloses all [`scroll`][struct@crate::EventControllerScroll#scroll] emissions
25 /// between two [`scroll-begin`][struct@crate::EventControllerScroll#scroll-begin] and
26 /// [`scroll-end`][struct@crate::EventControllerScroll#scroll-end] signals.
27 ///
28 /// The behavior of the event controller can be modified by the flags
29 /// given at creation time, or modified at a later point through
30 /// [`set_flags()`][Self::set_flags()] (e.g. because the scrolling
31 /// conditions of the widget changed).
32 ///
33 /// The controller can be set up to emit motion for either/both vertical
34 /// and horizontal scroll events through [`EventControllerScrollFlags::VERTICAL`][crate::EventControllerScrollFlags::VERTICAL],
35 /// [`EventControllerScrollFlags::HORIZONTAL`][crate::EventControllerScrollFlags::HORIZONTAL] and [`EventControllerScrollFlags::BOTH_AXES`][crate::EventControllerScrollFlags::BOTH_AXES].
36 /// If any axis is disabled, the respective [`scroll`][struct@crate::EventControllerScroll#scroll]
37 /// delta will be 0. Vertical scroll events will be translated to horizontal
38 /// motion for the devices incapable of horizontal scrolling.
39 ///
40 /// The event controller can also be forced to emit discrete events on all
41 /// devices through [`EventControllerScrollFlags::DISCRETE`][crate::EventControllerScrollFlags::DISCRETE]. This can be used
42 /// to implement discrete actions triggered through scroll events (e.g.
43 /// switching across combobox options).
44 ///
45 /// The [`EventControllerScrollFlags::KINETIC`][crate::EventControllerScrollFlags::KINETIC] flag toggles the emission of the
46 /// [`decelerate`][struct@crate::EventControllerScroll#decelerate] signal, emitted at the end
47 /// of scrolling with two X/Y velocity arguments that are consistent with the
48 /// motion that was received.
49 ///
50 /// ## Properties
51 ///
52 ///
53 /// #### `flags`
54 /// The flags affecting event controller behavior.
55 ///
56 /// Readable | Writeable
57 /// <details><summary><h4>EventController</h4></summary>
58 ///
59 ///
60 /// #### `name`
61 /// The name for this controller, typically used for debugging purposes.
62 ///
63 /// Readable | Writeable
64 ///
65 ///
66 /// #### `propagation-limit`
67 /// The limit for which events this controller will handle.
68 ///
69 /// Readable | Writeable
70 ///
71 ///
72 /// #### `propagation-phase`
73 /// The propagation phase at which this controller will handle events.
74 ///
75 /// Readable | Writeable
76 ///
77 ///
78 /// #### `widget`
79 /// The widget receiving the `GdkEvents` that the controller will handle.
80 ///
81 /// Readable
82 /// </details>
83 ///
84 /// ## Signals
85 ///
86 ///
87 /// #### `decelerate`
88 /// Emitted after scroll is finished if the
89 /// [`EventControllerScrollFlags::KINETIC`][crate::EventControllerScrollFlags::KINETIC] flag is set.
90 ///
91 /// @vel_x and @vel_y express the initial velocity that was
92 /// imprinted by the scroll events. @vel_x and @vel_y are expressed in
93 /// pixels/ms.
94 ///
95 ///
96 ///
97 ///
98 /// #### `scroll`
99 /// Signals that the widget should scroll by the
100 /// amount specified by @dx and @dy.
101 ///
102 /// For the representation unit of the deltas, see
103 /// [`EventControllerScroll::unit()`][crate::EventControllerScroll::unit()].
104 ///
105 ///
106 ///
107 ///
108 /// #### `scroll-begin`
109 /// Signals that a new scrolling operation has begun.
110 ///
111 /// It will only be emitted on devices capable of it.
112 ///
113 ///
114 ///
115 ///
116 /// #### `scroll-end`
117 /// Signals that a scrolling operation has finished.
118 ///
119 /// It will only be emitted on devices capable of it.
120 ///
121 ///
122 ///
123 /// # Implements
124 ///
125 /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
126 #[doc(alias = "GtkEventControllerScroll")]
127 pub struct EventControllerScroll(Object<ffi::GtkEventControllerScroll, ffi::GtkEventControllerScrollClass>) @extends EventController;
128
129 match fn {
130 type_ => || ffi::gtk_event_controller_scroll_get_type(),
131 }
132}
133
134impl EventControllerScroll {
135 /// Creates a new event controller that will handle scroll events.
136 /// ## `flags`
137 /// flags affecting the controller behavior
138 ///
139 /// # Returns
140 ///
141 /// a new [`EventControllerScroll`][crate::EventControllerScroll]
142 #[doc(alias = "gtk_event_controller_scroll_new")]
143 pub fn new(flags: EventControllerScrollFlags) -> EventControllerScroll {
144 assert_initialized_main_thread!();
145 unsafe {
146 EventController::from_glib_full(ffi::gtk_event_controller_scroll_new(flags.into_glib()))
147 .unsafe_cast()
148 }
149 }
150
151 // rustdoc-stripper-ignore-next
152 /// Creates a new builder-pattern struct instance to construct [`EventControllerScroll`] objects.
153 ///
154 /// This method returns an instance of [`EventControllerScrollBuilder`](crate::builders::EventControllerScrollBuilder) which can be used to create [`EventControllerScroll`] objects.
155 pub fn builder() -> EventControllerScrollBuilder {
156 EventControllerScrollBuilder::new()
157 }
158
159 /// Gets the flags conditioning the scroll controller behavior.
160 ///
161 /// # Returns
162 ///
163 /// the controller flags.
164 #[doc(alias = "gtk_event_controller_scroll_get_flags")]
165 #[doc(alias = "get_flags")]
166 pub fn flags(&self) -> EventControllerScrollFlags {
167 unsafe {
168 from_glib(ffi::gtk_event_controller_scroll_get_flags(
169 self.to_glib_none().0,
170 ))
171 }
172 }
173
174 /// Gets the scroll unit of the last
175 /// [`scroll`][struct@crate::EventControllerScroll#scroll] signal received.
176 ///
177 /// Always returns [`gdk::ScrollUnit::Wheel`][crate::gdk::ScrollUnit::Wheel] if the
178 /// [`EventControllerScrollFlags::DISCRETE`][crate::EventControllerScrollFlags::DISCRETE] flag is set.
179 ///
180 /// # Returns
181 ///
182 /// the scroll unit.
183 #[cfg(feature = "v4_8")]
184 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
185 #[doc(alias = "gtk_event_controller_scroll_get_unit")]
186 #[doc(alias = "get_unit")]
187 pub fn unit(&self) -> gdk::ScrollUnit {
188 unsafe {
189 from_glib(ffi::gtk_event_controller_scroll_get_unit(
190 self.to_glib_none().0,
191 ))
192 }
193 }
194
195 /// Sets the flags conditioning scroll controller behavior.
196 /// ## `flags`
197 /// flags affecting the controller behavior
198 #[doc(alias = "gtk_event_controller_scroll_set_flags")]
199 #[doc(alias = "flags")]
200 pub fn set_flags(&self, flags: EventControllerScrollFlags) {
201 unsafe {
202 ffi::gtk_event_controller_scroll_set_flags(self.to_glib_none().0, flags.into_glib());
203 }
204 }
205
206 /// Emitted after scroll is finished if the
207 /// [`EventControllerScrollFlags::KINETIC`][crate::EventControllerScrollFlags::KINETIC] flag is set.
208 ///
209 /// @vel_x and @vel_y express the initial velocity that was
210 /// imprinted by the scroll events. @vel_x and @vel_y are expressed in
211 /// pixels/ms.
212 /// ## `vel_x`
213 /// X velocity
214 /// ## `vel_y`
215 /// Y velocity
216 #[doc(alias = "decelerate")]
217 pub fn connect_decelerate<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
218 unsafe extern "C" fn decelerate_trampoline<
219 F: Fn(&EventControllerScroll, f64, f64) + 'static,
220 >(
221 this: *mut ffi::GtkEventControllerScroll,
222 vel_x: std::ffi::c_double,
223 vel_y: std::ffi::c_double,
224 f: glib::ffi::gpointer,
225 ) {
226 let f: &F = &*(f as *const F);
227 f(&from_glib_borrow(this), vel_x, vel_y)
228 }
229 unsafe {
230 let f: Box_<F> = Box_::new(f);
231 connect_raw(
232 self.as_ptr() as *mut _,
233 b"decelerate\0".as_ptr() as *const _,
234 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
235 decelerate_trampoline::<F> as *const (),
236 )),
237 Box_::into_raw(f),
238 )
239 }
240 }
241
242 /// Signals that the widget should scroll by the
243 /// amount specified by @dx and @dy.
244 ///
245 /// For the representation unit of the deltas, see
246 /// [`unit()`][Self::unit()].
247 /// ## `dx`
248 /// X delta
249 /// ## `dy`
250 /// Y delta
251 ///
252 /// # Returns
253 ///
254 /// [`true`] if the scroll event was handled,
255 /// [`false`] otherwise.
256 #[doc(alias = "scroll")]
257 pub fn connect_scroll<F: Fn(&Self, f64, f64) -> glib::Propagation + 'static>(
258 &self,
259 f: F,
260 ) -> SignalHandlerId {
261 unsafe extern "C" fn scroll_trampoline<
262 F: Fn(&EventControllerScroll, f64, f64) -> glib::Propagation + 'static,
263 >(
264 this: *mut ffi::GtkEventControllerScroll,
265 dx: std::ffi::c_double,
266 dy: std::ffi::c_double,
267 f: glib::ffi::gpointer,
268 ) -> glib::ffi::gboolean {
269 let f: &F = &*(f as *const F);
270 f(&from_glib_borrow(this), dx, dy).into_glib()
271 }
272 unsafe {
273 let f: Box_<F> = Box_::new(f);
274 connect_raw(
275 self.as_ptr() as *mut _,
276 b"scroll\0".as_ptr() as *const _,
277 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
278 scroll_trampoline::<F> as *const (),
279 )),
280 Box_::into_raw(f),
281 )
282 }
283 }
284
285 /// Signals that a new scrolling operation has begun.
286 ///
287 /// It will only be emitted on devices capable of it.
288 #[doc(alias = "scroll-begin")]
289 pub fn connect_scroll_begin<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
290 unsafe extern "C" fn scroll_begin_trampoline<F: Fn(&EventControllerScroll) + 'static>(
291 this: *mut ffi::GtkEventControllerScroll,
292 f: glib::ffi::gpointer,
293 ) {
294 let f: &F = &*(f as *const F);
295 f(&from_glib_borrow(this))
296 }
297 unsafe {
298 let f: Box_<F> = Box_::new(f);
299 connect_raw(
300 self.as_ptr() as *mut _,
301 b"scroll-begin\0".as_ptr() as *const _,
302 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
303 scroll_begin_trampoline::<F> as *const (),
304 )),
305 Box_::into_raw(f),
306 )
307 }
308 }
309
310 /// Signals that a scrolling operation has finished.
311 ///
312 /// It will only be emitted on devices capable of it.
313 #[doc(alias = "scroll-end")]
314 pub fn connect_scroll_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
315 unsafe extern "C" fn scroll_end_trampoline<F: Fn(&EventControllerScroll) + 'static>(
316 this: *mut ffi::GtkEventControllerScroll,
317 f: glib::ffi::gpointer,
318 ) {
319 let f: &F = &*(f as *const F);
320 f(&from_glib_borrow(this))
321 }
322 unsafe {
323 let f: Box_<F> = Box_::new(f);
324 connect_raw(
325 self.as_ptr() as *mut _,
326 b"scroll-end\0".as_ptr() as *const _,
327 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
328 scroll_end_trampoline::<F> as *const (),
329 )),
330 Box_::into_raw(f),
331 )
332 }
333 }
334
335 #[doc(alias = "flags")]
336 pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
337 unsafe extern "C" fn notify_flags_trampoline<F: Fn(&EventControllerScroll) + 'static>(
338 this: *mut ffi::GtkEventControllerScroll,
339 _param_spec: glib::ffi::gpointer,
340 f: glib::ffi::gpointer,
341 ) {
342 let f: &F = &*(f as *const F);
343 f(&from_glib_borrow(this))
344 }
345 unsafe {
346 let f: Box_<F> = Box_::new(f);
347 connect_raw(
348 self.as_ptr() as *mut _,
349 b"notify::flags\0".as_ptr() as *const _,
350 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
351 notify_flags_trampoline::<F> as *const (),
352 )),
353 Box_::into_raw(f),
354 )
355 }
356 }
357}
358
359impl Default for EventControllerScroll {
360 fn default() -> Self {
361 glib::object::Object::new::<Self>()
362 }
363}
364
365// rustdoc-stripper-ignore-next
366/// A [builder-pattern] type to construct [`EventControllerScroll`] objects.
367///
368/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
369#[must_use = "The builder must be built to be used"]
370pub struct EventControllerScrollBuilder {
371 builder: glib::object::ObjectBuilder<'static, EventControllerScroll>,
372}
373
374impl EventControllerScrollBuilder {
375 fn new() -> Self {
376 Self {
377 builder: glib::object::Object::builder(),
378 }
379 }
380
381 /// The flags affecting event controller behavior.
382 pub fn flags(self, flags: EventControllerScrollFlags) -> Self {
383 Self {
384 builder: self.builder.property("flags", flags),
385 }
386 }
387
388 /// The name for this controller, typically used for debugging purposes.
389 pub fn name(self, name: impl Into<glib::GString>) -> Self {
390 Self {
391 builder: self.builder.property("name", name.into()),
392 }
393 }
394
395 /// The limit for which events this controller will handle.
396 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
397 Self {
398 builder: self
399 .builder
400 .property("propagation-limit", propagation_limit),
401 }
402 }
403
404 /// The propagation phase at which this controller will handle events.
405 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
406 Self {
407 builder: self
408 .builder
409 .property("propagation-phase", propagation_phase),
410 }
411 }
412
413 // rustdoc-stripper-ignore-next
414 /// Build the [`EventControllerScroll`].
415 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
416 pub fn build(self) -> EventControllerScroll {
417 assert_initialized_main_thread!();
418 self.builder.build()
419 }
420}