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::{ffi, BaselinePosition, LayoutManager, Orientable, Orientation};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
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            let f: &F = &*(f as *const F);
226            f(&from_glib_borrow(this))
227        }
228        unsafe {
229            let f: Box_<F> = Box_::new(f);
230            connect_raw(
231                self.as_ptr() as *mut _,
232                c"notify::baseline-child".as_ptr() as *const _,
233                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
234                    notify_baseline_child_trampoline::<F> as *const (),
235                )),
236                Box_::into_raw(f),
237            )
238        }
239    }
240
241    #[doc(alias = "baseline-position")]
242    pub fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(
243        &self,
244        f: F,
245    ) -> SignalHandlerId {
246        unsafe extern "C" fn notify_baseline_position_trampoline<F: Fn(&BoxLayout) + 'static>(
247            this: *mut ffi::GtkBoxLayout,
248            _param_spec: glib::ffi::gpointer,
249            f: glib::ffi::gpointer,
250        ) {
251            let f: &F = &*(f as *const F);
252            f(&from_glib_borrow(this))
253        }
254        unsafe {
255            let f: Box_<F> = Box_::new(f);
256            connect_raw(
257                self.as_ptr() as *mut _,
258                c"notify::baseline-position".as_ptr() as *const _,
259                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
260                    notify_baseline_position_trampoline::<F> as *const (),
261                )),
262                Box_::into_raw(f),
263            )
264        }
265    }
266
267    #[doc(alias = "homogeneous")]
268    pub fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
269        unsafe extern "C" fn notify_homogeneous_trampoline<F: Fn(&BoxLayout) + 'static>(
270            this: *mut ffi::GtkBoxLayout,
271            _param_spec: glib::ffi::gpointer,
272            f: glib::ffi::gpointer,
273        ) {
274            let f: &F = &*(f as *const F);
275            f(&from_glib_borrow(this))
276        }
277        unsafe {
278            let f: Box_<F> = Box_::new(f);
279            connect_raw(
280                self.as_ptr() as *mut _,
281                c"notify::homogeneous".as_ptr() as *const _,
282                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
283                    notify_homogeneous_trampoline::<F> as *const (),
284                )),
285                Box_::into_raw(f),
286            )
287        }
288    }
289
290    #[doc(alias = "spacing")]
291    pub fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
292        unsafe extern "C" fn notify_spacing_trampoline<F: Fn(&BoxLayout) + 'static>(
293            this: *mut ffi::GtkBoxLayout,
294            _param_spec: glib::ffi::gpointer,
295            f: glib::ffi::gpointer,
296        ) {
297            let f: &F = &*(f as *const F);
298            f(&from_glib_borrow(this))
299        }
300        unsafe {
301            let f: Box_<F> = Box_::new(f);
302            connect_raw(
303                self.as_ptr() as *mut _,
304                c"notify::spacing".as_ptr() as *const _,
305                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
306                    notify_spacing_trampoline::<F> as *const (),
307                )),
308                Box_::into_raw(f),
309            )
310        }
311    }
312}
313
314impl Default for BoxLayout {
315    fn default() -> Self {
316        glib::object::Object::new::<Self>()
317    }
318}
319
320// rustdoc-stripper-ignore-next
321/// A [builder-pattern] type to construct [`BoxLayout`] objects.
322///
323/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
324#[must_use = "The builder must be built to be used"]
325pub struct BoxLayoutBuilder {
326    builder: glib::object::ObjectBuilder<'static, BoxLayout>,
327}
328
329impl BoxLayoutBuilder {
330    fn new() -> Self {
331        Self {
332            builder: glib::object::Object::builder(),
333        }
334    }
335
336    /// The child that determines the baseline of the box
337    /// in vertical layout.
338    ///
339    /// If the child does baseline positioning, then its baseline
340    /// is lined up with the baseline of the box. If it doesn't, then
341    /// the bottom edge of the child is used.
342    #[cfg(feature = "v4_12")]
343    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
344    pub fn baseline_child(self, baseline_child: i32) -> Self {
345        Self {
346            builder: self.builder.property("baseline-child", baseline_child),
347        }
348    }
349
350    /// The position of the allocated baseline within the extra space
351    /// allocated to each child.
352    ///
353    /// This property is only relevant for horizontal layouts containing
354    /// at least one child with a baseline alignment.
355    pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
356        Self {
357            builder: self
358                .builder
359                .property("baseline-position", baseline_position),
360        }
361    }
362
363    /// Whether the box layout should distribute the available space
364    /// equally among the children.
365    pub fn homogeneous(self, homogeneous: bool) -> Self {
366        Self {
367            builder: self.builder.property("homogeneous", homogeneous),
368        }
369    }
370
371    /// The space to put between the children.
372    pub fn spacing(self, spacing: i32) -> Self {
373        Self {
374            builder: self.builder.property("spacing", spacing),
375        }
376    }
377
378    /// The orientation of the orientable.
379    pub fn orientation(self, orientation: Orientation) -> Self {
380        Self {
381            builder: self.builder.property("orientation", orientation),
382        }
383    }
384
385    // rustdoc-stripper-ignore-next
386    /// Build the [`BoxLayout`].
387    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
388    pub fn build(self) -> BoxLayout {
389        assert_initialized_main_thread!();
390        self.builder.build()
391    }
392}