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
88mod sealed {
89 pub trait Sealed {}
90 impl<T: super::IsA<super::Scrollable>> Sealed for T {}
91}
92
93/// Trait containing all [`struct@Scrollable`] methods.
94///
95/// # Implementors
96///
97/// [`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]
98pub trait ScrollableExt: IsA<Scrollable> + sealed::Sealed + 'static {
99 /// Returns the size of a non-scrolling border around the
100 /// outside of the scrollable.
101 ///
102 /// An example for this would be treeview headers. GTK can use
103 /// this information to display overlaid graphics, like the
104 /// overshoot indication, at the right position.
105 ///
106 /// # Returns
107 ///
108 /// [`true`] if @border has been set
109 ///
110 /// ## `border`
111 /// return location for the results
112 #[doc(alias = "gtk_scrollable_get_border")]
113 #[doc(alias = "get_border")]
114 fn border(&self) -> Option<Border> {
115 unsafe {
116 let mut border = Border::uninitialized();
117 let ret = from_glib(ffi::gtk_scrollable_get_border(
118 self.as_ref().to_glib_none().0,
119 border.to_glib_none_mut().0,
120 ));
121 if ret {
122 Some(border)
123 } else {
124 None
125 }
126 }
127 }
128
129 /// Retrieves the [`Adjustment`][crate::Adjustment] used for horizontal scrolling.
130 ///
131 /// # Returns
132 ///
133 /// horizontal [`Adjustment`][crate::Adjustment].
134 #[doc(alias = "gtk_scrollable_get_hadjustment")]
135 #[doc(alias = "get_hadjustment")]
136 fn hadjustment(&self) -> Option<Adjustment> {
137 unsafe {
138 from_glib_none(ffi::gtk_scrollable_get_hadjustment(
139 self.as_ref().to_glib_none().0,
140 ))
141 }
142 }
143
144 /// Gets the horizontal [`ScrollablePolicy`][crate::ScrollablePolicy].
145 ///
146 /// # Returns
147 ///
148 /// The horizontal [`ScrollablePolicy`][crate::ScrollablePolicy].
149 #[doc(alias = "gtk_scrollable_get_hscroll_policy")]
150 #[doc(alias = "get_hscroll_policy")]
151 #[doc(alias = "hscroll-policy")]
152 fn hscroll_policy(&self) -> ScrollablePolicy {
153 unsafe {
154 from_glib(ffi::gtk_scrollable_get_hscroll_policy(
155 self.as_ref().to_glib_none().0,
156 ))
157 }
158 }
159
160 /// Retrieves the [`Adjustment`][crate::Adjustment] used for vertical scrolling.
161 ///
162 /// # Returns
163 ///
164 /// vertical [`Adjustment`][crate::Adjustment].
165 #[doc(alias = "gtk_scrollable_get_vadjustment")]
166 #[doc(alias = "get_vadjustment")]
167 fn vadjustment(&self) -> Option<Adjustment> {
168 unsafe {
169 from_glib_none(ffi::gtk_scrollable_get_vadjustment(
170 self.as_ref().to_glib_none().0,
171 ))
172 }
173 }
174
175 /// Gets the vertical [`ScrollablePolicy`][crate::ScrollablePolicy].
176 ///
177 /// # Returns
178 ///
179 /// The vertical [`ScrollablePolicy`][crate::ScrollablePolicy].
180 #[doc(alias = "gtk_scrollable_get_vscroll_policy")]
181 #[doc(alias = "get_vscroll_policy")]
182 #[doc(alias = "vscroll-policy")]
183 fn vscroll_policy(&self) -> ScrollablePolicy {
184 unsafe {
185 from_glib(ffi::gtk_scrollable_get_vscroll_policy(
186 self.as_ref().to_glib_none().0,
187 ))
188 }
189 }
190
191 /// Sets the horizontal adjustment of the [`Scrollable`][crate::Scrollable].
192 /// ## `hadjustment`
193 /// a [`Adjustment`][crate::Adjustment]
194 #[doc(alias = "gtk_scrollable_set_hadjustment")]
195 #[doc(alias = "hadjustment")]
196 fn set_hadjustment(&self, hadjustment: Option<&impl IsA<Adjustment>>) {
197 unsafe {
198 ffi::gtk_scrollable_set_hadjustment(
199 self.as_ref().to_glib_none().0,
200 hadjustment.map(|p| p.as_ref()).to_glib_none().0,
201 );
202 }
203 }
204
205 /// Sets the [`ScrollablePolicy`][crate::ScrollablePolicy].
206 ///
207 /// The policy determines whether horizontal scrolling should start
208 /// below the minimum width or below the natural width.
209 /// ## `policy`
210 /// the horizontal [`ScrollablePolicy`][crate::ScrollablePolicy]
211 #[doc(alias = "gtk_scrollable_set_hscroll_policy")]
212 #[doc(alias = "hscroll-policy")]
213 fn set_hscroll_policy(&self, policy: ScrollablePolicy) {
214 unsafe {
215 ffi::gtk_scrollable_set_hscroll_policy(
216 self.as_ref().to_glib_none().0,
217 policy.into_glib(),
218 );
219 }
220 }
221
222 /// Sets the vertical adjustment of the [`Scrollable`][crate::Scrollable].
223 /// ## `vadjustment`
224 /// a [`Adjustment`][crate::Adjustment]
225 #[doc(alias = "gtk_scrollable_set_vadjustment")]
226 #[doc(alias = "vadjustment")]
227 fn set_vadjustment(&self, vadjustment: Option<&impl IsA<Adjustment>>) {
228 unsafe {
229 ffi::gtk_scrollable_set_vadjustment(
230 self.as_ref().to_glib_none().0,
231 vadjustment.map(|p| p.as_ref()).to_glib_none().0,
232 );
233 }
234 }
235
236 /// Sets the [`ScrollablePolicy`][crate::ScrollablePolicy].
237 ///
238 /// The policy determines whether vertical scrolling should start
239 /// below the minimum height or below the natural height.
240 /// ## `policy`
241 /// the vertical [`ScrollablePolicy`][crate::ScrollablePolicy]
242 #[doc(alias = "gtk_scrollable_set_vscroll_policy")]
243 #[doc(alias = "vscroll-policy")]
244 fn set_vscroll_policy(&self, policy: ScrollablePolicy) {
245 unsafe {
246 ffi::gtk_scrollable_set_vscroll_policy(
247 self.as_ref().to_glib_none().0,
248 policy.into_glib(),
249 );
250 }
251 }
252
253 #[doc(alias = "hadjustment")]
254 fn connect_hadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
255 unsafe extern "C" fn notify_hadjustment_trampoline<
256 P: IsA<Scrollable>,
257 F: Fn(&P) + 'static,
258 >(
259 this: *mut ffi::GtkScrollable,
260 _param_spec: glib::ffi::gpointer,
261 f: glib::ffi::gpointer,
262 ) {
263 let f: &F = &*(f as *const F);
264 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
265 }
266 unsafe {
267 let f: Box_<F> = Box_::new(f);
268 connect_raw(
269 self.as_ptr() as *mut _,
270 b"notify::hadjustment\0".as_ptr() as *const _,
271 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
272 notify_hadjustment_trampoline::<Self, F> as *const (),
273 )),
274 Box_::into_raw(f),
275 )
276 }
277 }
278
279 #[doc(alias = "hscroll-policy")]
280 fn connect_hscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
281 unsafe extern "C" fn notify_hscroll_policy_trampoline<
282 P: IsA<Scrollable>,
283 F: Fn(&P) + 'static,
284 >(
285 this: *mut ffi::GtkScrollable,
286 _param_spec: glib::ffi::gpointer,
287 f: glib::ffi::gpointer,
288 ) {
289 let f: &F = &*(f as *const F);
290 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
291 }
292 unsafe {
293 let f: Box_<F> = Box_::new(f);
294 connect_raw(
295 self.as_ptr() as *mut _,
296 b"notify::hscroll-policy\0".as_ptr() as *const _,
297 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
298 notify_hscroll_policy_trampoline::<Self, F> as *const (),
299 )),
300 Box_::into_raw(f),
301 )
302 }
303 }
304
305 #[doc(alias = "vadjustment")]
306 fn connect_vadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
307 unsafe extern "C" fn notify_vadjustment_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 let f: &F = &*(f as *const F);
316 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
317 }
318 unsafe {
319 let f: Box_<F> = Box_::new(f);
320 connect_raw(
321 self.as_ptr() as *mut _,
322 b"notify::vadjustment\0".as_ptr() as *const _,
323 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
324 notify_vadjustment_trampoline::<Self, F> as *const (),
325 )),
326 Box_::into_raw(f),
327 )
328 }
329 }
330
331 #[doc(alias = "vscroll-policy")]
332 fn connect_vscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
333 unsafe extern "C" fn notify_vscroll_policy_trampoline<
334 P: IsA<Scrollable>,
335 F: Fn(&P) + 'static,
336 >(
337 this: *mut ffi::GtkScrollable,
338 _param_spec: glib::ffi::gpointer,
339 f: glib::ffi::gpointer,
340 ) {
341 let f: &F = &*(f as *const F);
342 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
343 }
344 unsafe {
345 let f: Box_<F> = Box_::new(f);
346 connect_raw(
347 self.as_ptr() as *mut _,
348 b"notify::vscroll-policy\0".as_ptr() as *const _,
349 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
350 notify_vscroll_policy_trampoline::<Self, F> as *const (),
351 )),
352 Box_::into_raw(f),
353 )
354 }
355 }
356}
357
358impl<O: IsA<Scrollable>> ScrollableExt for O {}