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
45use crate::{ffi, BaselinePosition, LayoutManager, Orientable, Orientation};
6use glib::{
7prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9translate::*,
10};
11use std::boxed::Boxas Box_;
1213glib::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")]
77pub struct BoxLayout(Object<ffi::GtkBoxLayout, ffi::GtkBoxLayoutClass>) @extends LayoutManager, @implements Orientable;
7879match fn {
80 type_ => || ffi::gtk_box_layout_get_type(),
81 }
82}
8384impl 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")]
93pub fn new(orientation: Orientation) -> BoxLayout {
94assert_initialized_main_thread!();
95unsafe {
96LayoutManager::from_glib_full(ffi::gtk_box_layout_new(orientation.into_glib()))
97 .unsafe_cast()
98 }
99 }
100101// 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.
105pub fn builder() -> BoxLayoutBuilder {
106BoxLayoutBuilder::new()
107 }
108109/// 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")]
120pub fn baseline_child(&self) -> i32 {
121unsafe { ffi::gtk_box_layout_get_baseline_child(self.to_glib_none().0) }
122 }
123124/// 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")]
132pub fn baseline_position(&self) -> BaselinePosition {
133unsafe {
134from_glib(ffi::gtk_box_layout_get_baseline_position(
135self.to_glib_none().0,
136 ))
137 }
138 }
139140/// 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")]
148pub fn is_homogeneous(&self) -> bool {
149unsafe { from_glib(ffi::gtk_box_layout_get_homogeneous(self.to_glib_none().0)) }
150 }
151152/// 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")]
159pub fn spacing(&self) -> u32 {
160unsafe { ffi::gtk_box_layout_get_spacing(self.to_glib_none().0) }
161 }
162163/// 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")]
171pub fn set_baseline_child(&self, child: i32) {
172unsafe {
173ffi::gtk_box_layout_set_baseline_child(self.to_glib_none().0, child);
174 }
175 }
176177/// 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")]
188pub fn set_baseline_position(&self, position: BaselinePosition) {
189unsafe {
190ffi::gtk_box_layout_set_baseline_position(self.to_glib_none().0, position.into_glib());
191 }
192 }
193194/// 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")]
200pub fn set_homogeneous(&self, homogeneous: bool) {
201unsafe {
202ffi::gtk_box_layout_set_homogeneous(self.to_glib_none().0, homogeneous.into_glib());
203 }
204 }
205206/// 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")]
211pub fn set_spacing(&self, spacing: u32) {
212unsafe {
213ffi::gtk_box_layout_set_spacing(self.to_glib_none().0, spacing);
214 }
215 }
216217#[cfg(feature = "v4_12")]
218 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
219 #[doc(alias = "baseline-child")]
220pub fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
221unsafe 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 ) {
226let f: &F = &*(fas *const F);
227f(&from_glib_borrow(this))
228 }
229unsafe {
230let f: Box_<F> = Box_::new(f);
231connect_raw(
232self.as_ptr() as *mut _,
233b"notify::baseline-child\0".as_ptr() as *const _,
234Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
235notify_baseline_child_trampoline::<F> as *const (),
236 )),
237Box_::into_raw(f),
238 )
239 }
240 }
241242#[doc(alias = "baseline-position")]
243pub fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(
244&self,
245 f: F,
246 ) -> SignalHandlerId {
247unsafe 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 ) {
252let f: &F = &*(fas *const F);
253f(&from_glib_borrow(this))
254 }
255unsafe {
256let f: Box_<F> = Box_::new(f);
257connect_raw(
258self.as_ptr() as *mut _,
259b"notify::baseline-position\0".as_ptr() as *const _,
260Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261notify_baseline_position_trampoline::<F> as *const (),
262 )),
263Box_::into_raw(f),
264 )
265 }
266 }
267268#[doc(alias = "homogeneous")]
269pub fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
270unsafe 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 ) {
275let f: &F = &*(fas *const F);
276f(&from_glib_borrow(this))
277 }
278unsafe {
279let f: Box_<F> = Box_::new(f);
280connect_raw(
281self.as_ptr() as *mut _,
282b"notify::homogeneous\0".as_ptr() as *const _,
283Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
284notify_homogeneous_trampoline::<F> as *const (),
285 )),
286Box_::into_raw(f),
287 )
288 }
289 }
290291#[doc(alias = "spacing")]
292pub fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
293unsafe 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 ) {
298let f: &F = &*(fas *const F);
299f(&from_glib_borrow(this))
300 }
301unsafe {
302let f: Box_<F> = Box_::new(f);
303connect_raw(
304self.as_ptr() as *mut _,
305b"notify::spacing\0".as_ptr() as *const _,
306Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
307notify_spacing_trampoline::<F> as *const (),
308 )),
309Box_::into_raw(f),
310 )
311 }
312 }
313}
314315impl Defaultfor BoxLayout {
316fn default() -> Self {
317 glib::object::Object::new::<Self>()
318 }
319}
320321// 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}
329330impl BoxLayoutBuilder {
331fn new() -> Self {
332Self {
333 builder: glib::object::Object::builder(),
334 }
335 }
336337/// 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")))]
345pub fn baseline_child(self, baseline_child: i32) -> Self {
346Self {
347 builder: self.builder.property("baseline-child", baseline_child),
348 }
349 }
350351/// 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.
356pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
357Self {
358 builder: self359.builder
360 .property("baseline-position", baseline_position),
361 }
362 }
363364/// Whether the box layout should distribute the available space
365 /// equally among the children.
366pub fn homogeneous(self, homogeneous: bool) -> Self {
367Self {
368 builder: self.builder.property("homogeneous", homogeneous),
369 }
370 }
371372/// The space to put between the children.
373pub fn spacing(self, spacing: i32) -> Self {
374Self {
375 builder: self.builder.property("spacing", spacing),
376 }
377 }
378379/// The orientation of the orientable.
380pub fn orientation(self, orientation: Orientation) -> Self {
381Self {
382 builder: self.builder.property("orientation", orientation),
383 }
384 }
385386// 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"]
389pub fn build(self) -> BoxLayout {
390assert_initialized_main_thread!();
391self.builder.build()
392 }
393}