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    #[doc(alias = "GtkEventControllerScroll")]
16    pub struct EventControllerScroll(Object<ffi::GtkEventControllerScroll, ffi::GtkEventControllerScrollClass>) @extends EventController;
17
18    match fn {
19        type_ => || ffi::gtk_event_controller_scroll_get_type(),
20    }
21}
22
23impl EventControllerScroll {
24    #[doc(alias = "gtk_event_controller_scroll_new")]
25    pub fn new(flags: EventControllerScrollFlags) -> EventControllerScroll {
26        assert_initialized_main_thread!();
27        unsafe {
28            EventController::from_glib_full(ffi::gtk_event_controller_scroll_new(flags.into_glib()))
29                .unsafe_cast()
30        }
31    }
32
33    // rustdoc-stripper-ignore-next
34    /// Creates a new builder-pattern struct instance to construct [`EventControllerScroll`] objects.
35    ///
36    /// This method returns an instance of [`EventControllerScrollBuilder`](crate::builders::EventControllerScrollBuilder) which can be used to create [`EventControllerScroll`] objects.
37    pub fn builder() -> EventControllerScrollBuilder {
38        EventControllerScrollBuilder::new()
39    }
40
41    #[doc(alias = "gtk_event_controller_scroll_get_flags")]
42    #[doc(alias = "get_flags")]
43    pub fn flags(&self) -> EventControllerScrollFlags {
44        unsafe {
45            from_glib(ffi::gtk_event_controller_scroll_get_flags(
46                self.to_glib_none().0,
47            ))
48        }
49    }
50
51    #[cfg(feature = "v4_8")]
52    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
53    #[doc(alias = "gtk_event_controller_scroll_get_unit")]
54    #[doc(alias = "get_unit")]
55    pub fn unit(&self) -> gdk::ScrollUnit {
56        unsafe {
57            from_glib(ffi::gtk_event_controller_scroll_get_unit(
58                self.to_glib_none().0,
59            ))
60        }
61    }
62
63    #[doc(alias = "gtk_event_controller_scroll_set_flags")]
64    #[doc(alias = "flags")]
65    pub fn set_flags(&self, flags: EventControllerScrollFlags) {
66        unsafe {
67            ffi::gtk_event_controller_scroll_set_flags(self.to_glib_none().0, flags.into_glib());
68        }
69    }
70
71    #[doc(alias = "decelerate")]
72    pub fn connect_decelerate<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
73        unsafe extern "C" fn decelerate_trampoline<
74            F: Fn(&EventControllerScroll, f64, f64) + 'static,
75        >(
76            this: *mut ffi::GtkEventControllerScroll,
77            vel_x: std::ffi::c_double,
78            vel_y: std::ffi::c_double,
79            f: glib::ffi::gpointer,
80        ) {
81            let f: &F = &*(f as *const F);
82            f(&from_glib_borrow(this), vel_x, vel_y)
83        }
84        unsafe {
85            let f: Box_<F> = Box_::new(f);
86            connect_raw(
87                self.as_ptr() as *mut _,
88                c"decelerate".as_ptr() as *const _,
89                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
90                    decelerate_trampoline::<F> as *const (),
91                )),
92                Box_::into_raw(f),
93            )
94        }
95    }
96
97    #[doc(alias = "scroll")]
98    pub fn connect_scroll<F: Fn(&Self, f64, f64) -> glib::Propagation + 'static>(
99        &self,
100        f: F,
101    ) -> SignalHandlerId {
102        unsafe extern "C" fn scroll_trampoline<
103            F: Fn(&EventControllerScroll, f64, f64) -> glib::Propagation + 'static,
104        >(
105            this: *mut ffi::GtkEventControllerScroll,
106            dx: std::ffi::c_double,
107            dy: std::ffi::c_double,
108            f: glib::ffi::gpointer,
109        ) -> glib::ffi::gboolean {
110            let f: &F = &*(f as *const F);
111            f(&from_glib_borrow(this), dx, dy).into_glib()
112        }
113        unsafe {
114            let f: Box_<F> = Box_::new(f);
115            connect_raw(
116                self.as_ptr() as *mut _,
117                c"scroll".as_ptr() as *const _,
118                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
119                    scroll_trampoline::<F> as *const (),
120                )),
121                Box_::into_raw(f),
122            )
123        }
124    }
125
126    #[doc(alias = "scroll-begin")]
127    pub fn connect_scroll_begin<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
128        unsafe extern "C" fn scroll_begin_trampoline<F: Fn(&EventControllerScroll) + 'static>(
129            this: *mut ffi::GtkEventControllerScroll,
130            f: glib::ffi::gpointer,
131        ) {
132            let f: &F = &*(f as *const F);
133            f(&from_glib_borrow(this))
134        }
135        unsafe {
136            let f: Box_<F> = Box_::new(f);
137            connect_raw(
138                self.as_ptr() as *mut _,
139                c"scroll-begin".as_ptr() as *const _,
140                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
141                    scroll_begin_trampoline::<F> as *const (),
142                )),
143                Box_::into_raw(f),
144            )
145        }
146    }
147
148    #[doc(alias = "scroll-end")]
149    pub fn connect_scroll_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150        unsafe extern "C" fn scroll_end_trampoline<F: Fn(&EventControllerScroll) + 'static>(
151            this: *mut ffi::GtkEventControllerScroll,
152            f: glib::ffi::gpointer,
153        ) {
154            let f: &F = &*(f as *const F);
155            f(&from_glib_borrow(this))
156        }
157        unsafe {
158            let f: Box_<F> = Box_::new(f);
159            connect_raw(
160                self.as_ptr() as *mut _,
161                c"scroll-end".as_ptr() as *const _,
162                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
163                    scroll_end_trampoline::<F> as *const (),
164                )),
165                Box_::into_raw(f),
166            )
167        }
168    }
169
170    #[doc(alias = "flags")]
171    pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
172        unsafe extern "C" fn notify_flags_trampoline<F: Fn(&EventControllerScroll) + 'static>(
173            this: *mut ffi::GtkEventControllerScroll,
174            _param_spec: glib::ffi::gpointer,
175            f: glib::ffi::gpointer,
176        ) {
177            let f: &F = &*(f as *const F);
178            f(&from_glib_borrow(this))
179        }
180        unsafe {
181            let f: Box_<F> = Box_::new(f);
182            connect_raw(
183                self.as_ptr() as *mut _,
184                c"notify::flags".as_ptr() as *const _,
185                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
186                    notify_flags_trampoline::<F> as *const (),
187                )),
188                Box_::into_raw(f),
189            )
190        }
191    }
192}
193
194impl Default for EventControllerScroll {
195    fn default() -> Self {
196        glib::object::Object::new::<Self>()
197    }
198}
199
200// rustdoc-stripper-ignore-next
201/// A [builder-pattern] type to construct [`EventControllerScroll`] objects.
202///
203/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
204#[must_use = "The builder must be built to be used"]
205pub struct EventControllerScrollBuilder {
206    builder: glib::object::ObjectBuilder<'static, EventControllerScroll>,
207}
208
209impl EventControllerScrollBuilder {
210    fn new() -> Self {
211        Self {
212            builder: glib::object::Object::builder(),
213        }
214    }
215
216    pub fn flags(self, flags: EventControllerScrollFlags) -> Self {
217        Self {
218            builder: self.builder.property("flags", flags),
219        }
220    }
221
222    pub fn name(self, name: impl Into<glib::GString>) -> Self {
223        Self {
224            builder: self.builder.property("name", name.into()),
225        }
226    }
227
228    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
229        Self {
230            builder: self
231                .builder
232                .property("propagation-limit", propagation_limit),
233        }
234    }
235
236    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
237        Self {
238            builder: self
239                .builder
240                .property("propagation-phase", propagation_phase),
241        }
242    }
243
244    // rustdoc-stripper-ignore-next
245    /// Build the [`EventControllerScroll`].
246    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
247    pub fn build(self) -> EventControllerScroll {
248        assert_initialized_main_thread!();
249        self.builder.build()
250    }
251}