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