Skip to main content

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