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::{ffi, Adjustment, Border, ScrollablePolicy};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// [`Scrollable`][crate::Scrollable] is 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 {
117 Some(border)
118 } else {
119 None
120 }
121 }
122 }
123
124 /// Retrieves the [`Adjustment`][crate::Adjustment] used for horizontal scrolling.
125 ///
126 /// # Returns
127 ///
128 /// horizontal [`Adjustment`][crate::Adjustment].
129 #[doc(alias = "gtk_scrollable_get_hadjustment")]
130 #[doc(alias = "get_hadjustment")]
131 fn hadjustment(&self) -> Option<Adjustment> {
132 unsafe {
133 from_glib_none(ffi::gtk_scrollable_get_hadjustment(
134 self.as_ref().to_glib_none().0,
135 ))
136 }
137 }
138
139 /// Gets the horizontal [`ScrollablePolicy`][crate::ScrollablePolicy].
140 ///
141 /// # Returns
142 ///
143 /// The horizontal [`ScrollablePolicy`][crate::ScrollablePolicy].
144 #[doc(alias = "gtk_scrollable_get_hscroll_policy")]
145 #[doc(alias = "get_hscroll_policy")]
146 #[doc(alias = "hscroll-policy")]
147 fn hscroll_policy(&self) -> ScrollablePolicy {
148 unsafe {
149 from_glib(ffi::gtk_scrollable_get_hscroll_policy(
150 self.as_ref().to_glib_none().0,
151 ))
152 }
153 }
154
155 /// Retrieves the [`Adjustment`][crate::Adjustment] used for vertical scrolling.
156 ///
157 /// # Returns
158 ///
159 /// vertical [`Adjustment`][crate::Adjustment].
160 #[doc(alias = "gtk_scrollable_get_vadjustment")]
161 #[doc(alias = "get_vadjustment")]
162 fn vadjustment(&self) -> Option<Adjustment> {
163 unsafe {
164 from_glib_none(ffi::gtk_scrollable_get_vadjustment(
165 self.as_ref().to_glib_none().0,
166 ))
167 }
168 }
169
170 /// Gets the vertical [`ScrollablePolicy`][crate::ScrollablePolicy].
171 ///
172 /// # Returns
173 ///
174 /// The vertical [`ScrollablePolicy`][crate::ScrollablePolicy].
175 #[doc(alias = "gtk_scrollable_get_vscroll_policy")]
176 #[doc(alias = "get_vscroll_policy")]
177 #[doc(alias = "vscroll-policy")]
178 fn vscroll_policy(&self) -> ScrollablePolicy {
179 unsafe {
180 from_glib(ffi::gtk_scrollable_get_vscroll_policy(
181 self.as_ref().to_glib_none().0,
182 ))
183 }
184 }
185
186 /// Sets the horizontal adjustment of the [`Scrollable`][crate::Scrollable].
187 /// ## `hadjustment`
188 /// a [`Adjustment`][crate::Adjustment]
189 #[doc(alias = "gtk_scrollable_set_hadjustment")]
190 #[doc(alias = "hadjustment")]
191 fn set_hadjustment(&self, hadjustment: Option<&impl IsA<Adjustment>>) {
192 unsafe {
193 ffi::gtk_scrollable_set_hadjustment(
194 self.as_ref().to_glib_none().0,
195 hadjustment.map(|p| p.as_ref()).to_glib_none().0,
196 );
197 }
198 }
199
200 /// Sets the [`ScrollablePolicy`][crate::ScrollablePolicy].
201 ///
202 /// The policy determines whether horizontal scrolling should start
203 /// below the minimum width or below the natural width.
204 /// ## `policy`
205 /// the horizontal [`ScrollablePolicy`][crate::ScrollablePolicy]
206 #[doc(alias = "gtk_scrollable_set_hscroll_policy")]
207 #[doc(alias = "hscroll-policy")]
208 fn set_hscroll_policy(&self, policy: ScrollablePolicy) {
209 unsafe {
210 ffi::gtk_scrollable_set_hscroll_policy(
211 self.as_ref().to_glib_none().0,
212 policy.into_glib(),
213 );
214 }
215 }
216
217 /// Sets the vertical adjustment of the [`Scrollable`][crate::Scrollable].
218 /// ## `vadjustment`
219 /// a [`Adjustment`][crate::Adjustment]
220 #[doc(alias = "gtk_scrollable_set_vadjustment")]
221 #[doc(alias = "vadjustment")]
222 fn set_vadjustment(&self, vadjustment: Option<&impl IsA<Adjustment>>) {
223 unsafe {
224 ffi::gtk_scrollable_set_vadjustment(
225 self.as_ref().to_glib_none().0,
226 vadjustment.map(|p| p.as_ref()).to_glib_none().0,
227 );
228 }
229 }
230
231 /// Sets the [`ScrollablePolicy`][crate::ScrollablePolicy].
232 ///
233 /// The policy determines whether vertical scrolling should start
234 /// below the minimum height or below the natural height.
235 /// ## `policy`
236 /// the vertical [`ScrollablePolicy`][crate::ScrollablePolicy]
237 #[doc(alias = "gtk_scrollable_set_vscroll_policy")]
238 #[doc(alias = "vscroll-policy")]
239 fn set_vscroll_policy(&self, policy: ScrollablePolicy) {
240 unsafe {
241 ffi::gtk_scrollable_set_vscroll_policy(
242 self.as_ref().to_glib_none().0,
243 policy.into_glib(),
244 );
245 }
246 }
247
248 #[doc(alias = "hadjustment")]
249 fn connect_hadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
250 unsafe extern "C" fn notify_hadjustment_trampoline<
251 P: IsA<Scrollable>,
252 F: Fn(&P) + 'static,
253 >(
254 this: *mut ffi::GtkScrollable,
255 _param_spec: glib::ffi::gpointer,
256 f: glib::ffi::gpointer,
257 ) {
258 let f: &F = &*(f as *const F);
259 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
260 }
261 unsafe {
262 let f: Box_<F> = Box_::new(f);
263 connect_raw(
264 self.as_ptr() as *mut _,
265 c"notify::hadjustment".as_ptr() as *const _,
266 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
267 notify_hadjustment_trampoline::<Self, F> as *const (),
268 )),
269 Box_::into_raw(f),
270 )
271 }
272 }
273
274 #[doc(alias = "hscroll-policy")]
275 fn connect_hscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
276 unsafe extern "C" fn notify_hscroll_policy_trampoline<
277 P: IsA<Scrollable>,
278 F: Fn(&P) + 'static,
279 >(
280 this: *mut ffi::GtkScrollable,
281 _param_spec: glib::ffi::gpointer,
282 f: glib::ffi::gpointer,
283 ) {
284 let f: &F = &*(f as *const F);
285 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
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 let f: &F = &*(f as *const F);
311 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
312 }
313 unsafe {
314 let f: Box_<F> = Box_::new(f);
315 connect_raw(
316 self.as_ptr() as *mut _,
317 c"notify::vadjustment".as_ptr() as *const _,
318 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319 notify_vadjustment_trampoline::<Self, F> as *const (),
320 )),
321 Box_::into_raw(f),
322 )
323 }
324 }
325
326 #[doc(alias = "vscroll-policy")]
327 fn connect_vscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
328 unsafe extern "C" fn notify_vscroll_policy_trampoline<
329 P: IsA<Scrollable>,
330 F: Fn(&P) + 'static,
331 >(
332 this: *mut ffi::GtkScrollable,
333 _param_spec: glib::ffi::gpointer,
334 f: glib::ffi::gpointer,
335 ) {
336 let f: &F = &*(f as *const F);
337 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
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() as *const _,
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 {}