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