Skip to main content

gtk4/auto/
scrollable.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::{Adjustment, Border, ScrollablePolicy, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    ///  property values are correct and up
15    ///   to date, for example using [`AdjustmentExt::configure()`][crate::prelude::AdjustmentExt::configure()].
16    ///
17    /// - When any of the adjustments emits the [`value-changed`][struct@crate::Adjustment#value-changed]
18    ///   signal, the scrollable widget should scroll its contents.
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `hadjustment`
24    ///  Horizontal [`Adjustment`][crate::Adjustment] of the scrollable widget.
25    ///
26    /// This adjustment is shared between the scrollable widget and its parent.
27    ///
28    /// Readable | Writable | Construct
29    ///
30    ///
31    /// #### `hscroll-policy`
32    ///  Determines when horizontal scrolling should start.
33    ///
34    /// Readable | Writable
35    ///
36    ///
37    /// #### `vadjustment`
38    ///  Vertical [`Adjustment`][crate::Adjustment] of the scrollable widget.
39    ///
40    /// This adjustment is shared between the scrollable widget and its parent.
41    ///
42    /// Readable | Writable | Construct
43    ///
44    ///
45    /// #### `vscroll-policy`
46    ///  Determines when vertical scrolling should start.
47    ///
48    /// Readable | Writable
49    ///
50    /// # Implements
51    ///
52    /// [`ScrollableExt`][trait@crate::prelude::ScrollableExt]
53    #[doc(alias = "GtkScrollable")]
54    pub struct Scrollable(Interface<ffi::GtkScrollable, ffi::GtkScrollableInterface>);
55
56    match fn {
57        type_ => || ffi::gtk_scrollable_get_type(),
58    }
59}
60
61impl Scrollable {
62    pub const NONE: Option<&'static Scrollable> = None;
63}
64
65/// Trait containing all [`struct@Scrollable`] methods.
66///
67/// # Implementors
68///
69/// [`ColumnView`][struct@crate::ColumnView], [`GridView`][struct@crate::GridView], [`IconView`][struct@crate::IconView], [`ListBase`][struct@crate::ListBase], [`ListView`][struct@crate::ListView], [`Scrollable`][struct@crate::Scrollable], [`TextView`][struct@crate::TextView], [`TreeView`][struct@crate::TreeView], [`Viewport`][struct@crate::Viewport]
70pub trait ScrollableExt: IsA<Scrollable> + 'static {
71    /// Returns the size of a non-scrolling border around the
72    /// outside of the scrollable.
73    ///
74    /// An example for this would be treeview headers. GTK can use
75    /// this information to display overlaid graphics, like the
76    /// overshoot indication, at the right position.
77    ///
78    /// # Returns
79    ///
80    /// [`true`] if @border has been set
81    ///
82    /// ## `border`
83    /// return location for the results
84    #[doc(alias = "gtk_scrollable_get_border")]
85    #[doc(alias = "get_border")]
86    fn border(&self) -> Option<Border> {
87        unsafe {
88            let mut border = Border::uninitialized();
89            let ret = from_glib(ffi::gtk_scrollable_get_border(
90                self.as_ref().to_glib_none().0,
91                border.to_glib_none_mut().0,
92            ));
93            if ret { Some(border) } else { None }
94        }
95    }
96
97    /// Retrieves the [`Adjustment`][crate::Adjustment] used for horizontal scrolling.
98    ///
99    /// # Returns
100    ///
101    /// horizontal [`Adjustment`][crate::Adjustment].
102    #[doc(alias = "gtk_scrollable_get_hadjustment")]
103    #[doc(alias = "get_hadjustment")]
104    fn hadjustment(&self) -> Option<Adjustment> {
105        unsafe {
106            from_glib_none(ffi::gtk_scrollable_get_hadjustment(
107                self.as_ref().to_glib_none().0,
108            ))
109        }
110    }
111
112    /// Gets the horizontal [`ScrollablePolicy`][crate::ScrollablePolicy].
113    ///
114    /// # Returns
115    ///
116    /// The horizontal [`ScrollablePolicy`][crate::ScrollablePolicy].
117    #[doc(alias = "gtk_scrollable_get_hscroll_policy")]
118    #[doc(alias = "get_hscroll_policy")]
119    #[doc(alias = "hscroll-policy")]
120    fn hscroll_policy(&self) -> ScrollablePolicy {
121        unsafe {
122            from_glib(ffi::gtk_scrollable_get_hscroll_policy(
123                self.as_ref().to_glib_none().0,
124            ))
125        }
126    }
127
128    /// Retrieves the [`Adjustment`][crate::Adjustment] used for vertical scrolling.
129    ///
130    /// # Returns
131    ///
132    /// vertical [`Adjustment`][crate::Adjustment].
133    #[doc(alias = "gtk_scrollable_get_vadjustment")]
134    #[doc(alias = "get_vadjustment")]
135    fn vadjustment(&self) -> Option<Adjustment> {
136        unsafe {
137            from_glib_none(ffi::gtk_scrollable_get_vadjustment(
138                self.as_ref().to_glib_none().0,
139            ))
140        }
141    }
142
143    /// Gets the vertical [`ScrollablePolicy`][crate::ScrollablePolicy].
144    ///
145    /// # Returns
146    ///
147    /// The vertical [`ScrollablePolicy`][crate::ScrollablePolicy].
148    #[doc(alias = "gtk_scrollable_get_vscroll_policy")]
149    #[doc(alias = "get_vscroll_policy")]
150    #[doc(alias = "vscroll-policy")]
151    fn vscroll_policy(&self) -> ScrollablePolicy {
152        unsafe {
153            from_glib(ffi::gtk_scrollable_get_vscroll_policy(
154                self.as_ref().to_glib_none().0,
155            ))
156        }
157    }
158
159    /// Sets the horizontal adjustment of the [`Scrollable`][crate::Scrollable].
160    /// ## `hadjustment`
161    /// a [`Adjustment`][crate::Adjustment]
162    #[doc(alias = "gtk_scrollable_set_hadjustment")]
163    #[doc(alias = "hadjustment")]
164    fn set_hadjustment(&self, hadjustment: Option<&impl IsA<Adjustment>>) {
165        unsafe {
166            ffi::gtk_scrollable_set_hadjustment(
167                self.as_ref().to_glib_none().0,
168                hadjustment.map(|p| p.as_ref()).to_glib_none().0,
169            );
170        }
171    }
172
173    /// Sets the [`ScrollablePolicy`][crate::ScrollablePolicy].
174    ///
175    /// The policy determines whether horizontal scrolling should start
176    /// below the minimum width or below the natural width.
177    /// ## `policy`
178    /// the horizontal [`ScrollablePolicy`][crate::ScrollablePolicy]
179    #[doc(alias = "gtk_scrollable_set_hscroll_policy")]
180    #[doc(alias = "hscroll-policy")]
181    fn set_hscroll_policy(&self, policy: ScrollablePolicy) {
182        unsafe {
183            ffi::gtk_scrollable_set_hscroll_policy(
184                self.as_ref().to_glib_none().0,
185                policy.into_glib(),
186            );
187        }
188    }
189
190    /// Sets the vertical adjustment of the [`Scrollable`][crate::Scrollable].
191    /// ## `vadjustment`
192    /// a [`Adjustment`][crate::Adjustment]
193    #[doc(alias = "gtk_scrollable_set_vadjustment")]
194    #[doc(alias = "vadjustment")]
195    fn set_vadjustment(&self, vadjustment: Option<&impl IsA<Adjustment>>) {
196        unsafe {
197            ffi::gtk_scrollable_set_vadjustment(
198                self.as_ref().to_glib_none().0,
199                vadjustment.map(|p| p.as_ref()).to_glib_none().0,
200            );
201        }
202    }
203
204    /// Sets the [`ScrollablePolicy`][crate::ScrollablePolicy].
205    ///
206    /// The policy determines whether vertical scrolling should start
207    /// below the minimum height or below the natural height.
208    /// ## `policy`
209    /// the vertical [`ScrollablePolicy`][crate::ScrollablePolicy]
210    #[doc(alias = "gtk_scrollable_set_vscroll_policy")]
211    #[doc(alias = "vscroll-policy")]
212    fn set_vscroll_policy(&self, policy: ScrollablePolicy) {
213        unsafe {
214            ffi::gtk_scrollable_set_vscroll_policy(
215                self.as_ref().to_glib_none().0,
216                policy.into_glib(),
217            );
218        }
219    }
220
221    #[doc(alias = "hadjustment")]
222    fn connect_hadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
223        unsafe extern "C" fn notify_hadjustment_trampoline<
224            P: IsA<Scrollable>,
225            F: Fn(&P) + 'static,
226        >(
227            this: *mut ffi::GtkScrollable,
228            _param_spec: glib::ffi::gpointer,
229            f: glib::ffi::gpointer,
230        ) {
231            unsafe {
232                let f: &F = &*(f as *const F);
233                f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
234            }
235        }
236        unsafe {
237            let f: Box_<F> = Box_::new(f);
238            connect_raw(
239                self.as_ptr() as *mut _,
240                c"notify::hadjustment".as_ptr(),
241                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
242                    notify_hadjustment_trampoline::<Self, F> as *const (),
243                )),
244                Box_::into_raw(f),
245            )
246        }
247    }
248
249    #[doc(alias = "hscroll-policy")]
250    fn connect_hscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
251        unsafe extern "C" fn notify_hscroll_policy_trampoline<
252            P: IsA<Scrollable>,
253            F: Fn(&P) + 'static,
254        >(
255            this: *mut ffi::GtkScrollable,
256            _param_spec: glib::ffi::gpointer,
257            f: glib::ffi::gpointer,
258        ) {
259            unsafe {
260                let f: &F = &*(f as *const F);
261                f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
262            }
263        }
264        unsafe {
265            let f: Box_<F> = Box_::new(f);
266            connect_raw(
267                self.as_ptr() as *mut _,
268                c"notify::hscroll-policy".as_ptr(),
269                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270                    notify_hscroll_policy_trampoline::<Self, F> as *const (),
271                )),
272                Box_::into_raw(f),
273            )
274        }
275    }
276
277    #[doc(alias = "vadjustment")]
278    fn connect_vadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
279        unsafe extern "C" fn notify_vadjustment_trampoline<
280            P: IsA<Scrollable>,
281            F: Fn(&P) + 'static,
282        >(
283            this: *mut ffi::GtkScrollable,
284            _param_spec: glib::ffi::gpointer,
285            f: glib::ffi::gpointer,
286        ) {
287            unsafe {
288                let f: &F = &*(f as *const F);
289                f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
290            }
291        }
292        unsafe {
293            let f: Box_<F> = Box_::new(f);
294            connect_raw(
295                self.as_ptr() as *mut _,
296                c"notify::vadjustment".as_ptr(),
297                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
298                    notify_vadjustment_trampoline::<Self, F> as *const (),
299                )),
300                Box_::into_raw(f),
301            )
302        }
303    }
304
305    #[doc(alias = "vscroll-policy")]
306    fn connect_vscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
307        unsafe extern "C" fn notify_vscroll_policy_trampoline<
308            P: IsA<Scrollable>,
309            F: Fn(&P) + 'static,
310        >(
311            this: *mut ffi::GtkScrollable,
312            _param_spec: glib::ffi::gpointer,
313            f: glib::ffi::gpointer,
314        ) {
315            unsafe {
316                let f: &F = &*(f as *const F);
317                f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
318            }
319        }
320        unsafe {
321            let f: Box_<F> = Box_::new(f);
322            connect_raw(
323                self.as_ptr() as *mut _,
324                c"notify::vscroll-policy".as_ptr(),
325                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
326                    notify_vscroll_policy_trampoline::<Self, F> as *const (),
327                )),
328                Box_::into_raw(f),
329            )
330        }
331    }
332}
333
334impl<O: IsA<Scrollable>> ScrollableExt for O {}