Skip to main content

gtk4/auto/
box_layout.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::{BaselinePosition, LayoutManager, Orientable, Orientation, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// Arranges children in a single row or column.
15    ///
16    /// Whether it is a row or column depends on the value of its
17    /// [`orientation`][struct@crate::Orientable#orientation] property. Within the other dimension
18    /// all children all allocated the same size. The [`BoxLayout`][crate::BoxLayout] will respect
19    /// the [`halign`][struct@crate::Widget#halign] and [`valign`][struct@crate::Widget#valign]
20    /// properties of each child widget.
21    ///
22    /// If you want all children to be assigned the same size, you can use
23    /// the [`homogeneous`][struct@crate::BoxLayout#homogeneous] property.
24    ///
25    /// If you want to specify the amount of space placed between each child,
26    /// you can use the [`spacing`][struct@crate::BoxLayout#spacing] property.
27    ///
28    /// ## Properties
29    ///
30    ///
31    /// #### `baseline-child`
32    ///  The child that determines the baseline of the box
33    /// in vertical layout.
34    ///
35    /// If the child does baseline positioning, then its baseline
36    /// is lined up with the baseline of the box. If it doesn't, then
37    /// the bottom edge of the child is used.
38    ///
39    /// Readable | Writeable
40    ///
41    ///
42    /// #### `baseline-position`
43    ///  The position of the allocated baseline within the extra space
44    /// allocated to each child.
45    ///
46    /// This property is only relevant for horizontal layouts containing
47    /// at least one child with a baseline alignment.
48    ///
49    /// Readable | Writeable
50    ///
51    ///
52    /// #### `homogeneous`
53    ///  Whether the box layout should distribute the available space
54    /// equally among the children.
55    ///
56    /// Readable | Writeable
57    ///
58    ///
59    /// #### `spacing`
60    ///  The space to put between the children.
61    ///
62    /// Readable | Writeable
63    /// <details><summary><h4>Orientable</h4></summary>
64    ///
65    ///
66    /// #### `orientation`
67    ///  The orientation of the orientable.
68    ///
69    /// Readable | Writeable
70    /// </details>
71    ///
72    /// # Implements
73    ///
74    /// [`LayoutManagerExt`][trait@crate::prelude::LayoutManagerExt], [`trait@glib::ObjectExt`], [`OrientableExt`][trait@crate::prelude::OrientableExt]
75    #[doc(alias = "GtkBoxLayout")]
76    pub struct BoxLayout(Object<ffi::GtkBoxLayout, ffi::GtkBoxLayoutClass>) @extends LayoutManager, @implements Orientable;
77
78    match fn {
79        type_ => || ffi::gtk_box_layout_get_type(),
80    }
81}
82
83impl BoxLayout {
84    /// Creates a new [`BoxLayout`][crate::BoxLayout].
85    /// ## `orientation`
86    /// the orientation for the new layout
87    ///
88    /// # Returns
89    ///
90    /// a new box layout
91    #[doc(alias = "gtk_box_layout_new")]
92    pub fn new(orientation: Orientation) -> BoxLayout {
93        assert_initialized_main_thread!();
94        unsafe {
95            LayoutManager::from_glib_full(ffi::gtk_box_layout_new(orientation.into_glib()))
96                .unsafe_cast()
97        }
98    }
99
100    // rustdoc-stripper-ignore-next
101    /// Creates a new builder-pattern struct instance to construct [`BoxLayout`] objects.
102    ///
103    /// This method returns an instance of [`BoxLayoutBuilder`](crate::builders::BoxLayoutBuilder) which can be used to create [`BoxLayout`] objects.
104    pub fn builder() -> BoxLayoutBuilder {
105        BoxLayoutBuilder::new()
106    }
107
108    /// Gets the value set by gtk_box_layout_set_baseline_child().
109    ///
110    /// # Returns
111    ///
112    /// the index of the child that determines the baseline
113    ///     in vertical layout, or -1
114    #[cfg(feature = "v4_12")]
115    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
116    #[doc(alias = "gtk_box_layout_get_baseline_child")]
117    #[doc(alias = "get_baseline_child")]
118    #[doc(alias = "baseline-child")]
119    pub fn baseline_child(&self) -> i32 {
120        unsafe { ffi::gtk_box_layout_get_baseline_child(self.to_glib_none().0) }
121    }
122
123    /// Gets the value set by gtk_box_layout_set_baseline_position().
124    ///
125    /// # Returns
126    ///
127    /// the baseline position
128    #[doc(alias = "gtk_box_layout_get_baseline_position")]
129    #[doc(alias = "get_baseline_position")]
130    #[doc(alias = "baseline-position")]
131    pub fn baseline_position(&self) -> BaselinePosition {
132        unsafe {
133            from_glib(ffi::gtk_box_layout_get_baseline_position(
134                self.to_glib_none().0,
135            ))
136        }
137    }
138
139    /// Returns whether the layout is set to be homogeneous.
140    ///
141    /// # Returns
142    ///
143    /// [`true`] if the layout is homogeneous
144    #[doc(alias = "gtk_box_layout_get_homogeneous")]
145    #[doc(alias = "get_homogeneous")]
146    #[doc(alias = "homogeneous")]
147    pub fn is_homogeneous(&self) -> bool {
148        unsafe { from_glib(ffi::gtk_box_layout_get_homogeneous(self.to_glib_none().0)) }
149    }
150
151    /// Returns the space that @self puts between children.
152    ///
153    /// # Returns
154    ///
155    /// the spacing of the layout
156    #[doc(alias = "gtk_box_layout_get_spacing")]
157    #[doc(alias = "get_spacing")]
158    pub fn spacing(&self) -> u32 {
159        unsafe { ffi::gtk_box_layout_get_spacing(self.to_glib_none().0) }
160    }
161
162    /// Sets the index of the child that determines the baseline
163    /// in vertical layout.
164    /// ## `child`
165    /// the child position, or -1
166    #[cfg(feature = "v4_12")]
167    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
168    #[doc(alias = "gtk_box_layout_set_baseline_child")]
169    #[doc(alias = "baseline-child")]
170    pub fn set_baseline_child(&self, child: i32) {
171        unsafe {
172            ffi::gtk_box_layout_set_baseline_child(self.to_glib_none().0, child);
173        }
174    }
175
176    /// Sets the baseline position of a box layout.
177    ///
178    /// The baseline position affects only horizontal boxes with at least one
179    /// baseline aligned child. If there is more vertical space available than
180    /// requested, and the baseline is not allocated by the parent then the
181    /// given @position is used to allocate the baseline within the extra
182    /// space available.
183    /// ## `position`
184    /// a [`BaselinePosition`][crate::BaselinePosition]
185    #[doc(alias = "gtk_box_layout_set_baseline_position")]
186    #[doc(alias = "baseline-position")]
187    pub fn set_baseline_position(&self, position: BaselinePosition) {
188        unsafe {
189            ffi::gtk_box_layout_set_baseline_position(self.to_glib_none().0, position.into_glib());
190        }
191    }
192
193    /// Sets whether the box layout will allocate the same
194    /// size to all children.
195    /// ## `homogeneous`
196    /// [`true`] to set the box layout as homogeneous
197    #[doc(alias = "gtk_box_layout_set_homogeneous")]
198    #[doc(alias = "homogeneous")]
199    pub fn set_homogeneous(&self, homogeneous: bool) {
200        unsafe {
201            ffi::gtk_box_layout_set_homogeneous(self.to_glib_none().0, homogeneous.into_glib());
202        }
203    }
204
205    /// Sets how much spacing to put between children.
206    /// ## `spacing`
207    /// the spacing to apply between children
208    #[doc(alias = "gtk_box_layout_set_spacing")]
209    #[doc(alias = "spacing")]
210    pub fn set_spacing(&self, spacing: u32) {
211        unsafe {
212            ffi::gtk_box_layout_set_spacing(self.to_glib_none().0, spacing);
213        }
214    }
215
216    #[cfg(feature = "v4_12")]
217    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
218    #[doc(alias = "baseline-child")]
219    pub fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
220        unsafe extern "C" fn notify_baseline_child_trampoline<F: Fn(&BoxLayout) + 'static>(
221            this: *mut ffi::GtkBoxLayout,
222            _param_spec: glib::ffi::gpointer,
223            f: glib::ffi::gpointer,
224        ) {
225            unsafe {
226                let f: &F = &*(f as *const F);
227                f(&from_glib_borrow(this))
228            }
229        }
230        unsafe {
231            let f: Box_<F> = Box_::new(f);
232            connect_raw(
233                self.as_ptr() as *mut _,
234                c"notify::baseline-child".as_ptr() as *const _,
235                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236                    notify_baseline_child_trampoline::<F> as *const (),
237                )),
238                Box_::into_raw(f),
239            )
240        }
241    }
242
243    #[doc(alias = "baseline-position")]
244    pub fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(
245        &self,
246        f: F,
247    ) -> SignalHandlerId {
248        unsafe extern "C" fn notify_baseline_position_trampoline<F: Fn(&BoxLayout) + 'static>(
249            this: *mut ffi::GtkBoxLayout,
250            _param_spec: glib::ffi::gpointer,
251            f: glib::ffi::gpointer,
252        ) {
253            unsafe {
254                let f: &F = &*(f as *const F);
255                f(&from_glib_borrow(this))
256            }
257        }
258        unsafe {
259            let f: Box_<F> = Box_::new(f);
260            connect_raw(
261                self.as_ptr() as *mut _,
262                c"notify::baseline-position".as_ptr() as *const _,
263                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
264                    notify_baseline_position_trampoline::<F> as *const (),
265                )),
266                Box_::into_raw(f),
267            )
268        }
269    }
270
271    #[doc(alias = "homogeneous")]
272    pub fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
273        unsafe extern "C" fn notify_homogeneous_trampoline<F: Fn(&BoxLayout) + 'static>(
274            this: *mut ffi::GtkBoxLayout,
275            _param_spec: glib::ffi::gpointer,
276            f: glib::ffi::gpointer,
277        ) {
278            unsafe {
279                let f: &F = &*(f as *const F);
280                f(&from_glib_borrow(this))
281            }
282        }
283        unsafe {
284            let f: Box_<F> = Box_::new(f);
285            connect_raw(
286                self.as_ptr() as *mut _,
287                c"notify::homogeneous".as_ptr() as *const _,
288                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
289                    notify_homogeneous_trampoline::<F> as *const (),
290                )),
291                Box_::into_raw(f),
292            )
293        }
294    }
295
296    #[doc(alias = "spacing")]
297    pub fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
298        unsafe extern "C" fn notify_spacing_trampoline<F: Fn(&BoxLayout) + 'static>(
299            this: *mut ffi::GtkBoxLayout,
300            _param_spec: glib::ffi::gpointer,
301            f: glib::ffi::gpointer,
302        ) {
303            unsafe {
304                let f: &F = &*(f as *const F);
305                f(&from_glib_borrow(this))
306            }
307        }
308        unsafe {
309            let f: Box_<F> = Box_::new(f);
310            connect_raw(
311                self.as_ptr() as *mut _,
312                c"notify::spacing".as_ptr() as *const _,
313                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
314                    notify_spacing_trampoline::<F> as *const (),
315                )),
316                Box_::into_raw(f),
317            )
318        }
319    }
320}
321
322impl Default for BoxLayout {
323    fn default() -> Self {
324        glib::object::Object::new::<Self>()
325    }
326}
327
328// rustdoc-stripper-ignore-next
329/// A [builder-pattern] type to construct [`BoxLayout`] objects.
330///
331/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
332#[must_use = "The builder must be built to be used"]
333pub struct BoxLayoutBuilder {
334    builder: glib::object::ObjectBuilder<'static, BoxLayout>,
335}
336
337impl BoxLayoutBuilder {
338    fn new() -> Self {
339        Self {
340            builder: glib::object::Object::builder(),
341        }
342    }
343
344    /// The child that determines the baseline of the box
345    /// in vertical layout.
346    ///
347    /// If the child does baseline positioning, then its baseline
348    /// is lined up with the baseline of the box. If it doesn't, then
349    /// the bottom edge of the child is used.
350    #[cfg(feature = "v4_12")]
351    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
352    pub fn baseline_child(self, baseline_child: i32) -> Self {
353        Self {
354            builder: self.builder.property("baseline-child", baseline_child),
355        }
356    }
357
358    /// The position of the allocated baseline within the extra space
359    /// allocated to each child.
360    ///
361    /// This property is only relevant for horizontal layouts containing
362    /// at least one child with a baseline alignment.
363    pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
364        Self {
365            builder: self
366                .builder
367                .property("baseline-position", baseline_position),
368        }
369    }
370
371    /// Whether the box layout should distribute the available space
372    /// equally among the children.
373    pub fn homogeneous(self, homogeneous: bool) -> Self {
374        Self {
375            builder: self.builder.property("homogeneous", homogeneous),
376        }
377    }
378
379    /// The space to put between the children.
380    pub fn spacing(self, spacing: i32) -> Self {
381        Self {
382            builder: self.builder.property("spacing", spacing),
383        }
384    }
385
386    /// The orientation of the orientable.
387    pub fn orientation(self, orientation: Orientation) -> Self {
388        Self {
389            builder: self.builder.property("orientation", orientation),
390        }
391    }
392
393    // rustdoc-stripper-ignore-next
394    /// Build the [`BoxLayout`].
395    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
396    pub fn build(self) -> BoxLayout {
397        assert_initialized_main_thread!();
398        self.builder.build()
399    }
400}