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