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/// 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")]
76pub struct BoxLayout(Object<ffi::GtkBoxLayout, ffi::GtkBoxLayoutClass>) @extends LayoutManager, @implements Orientable;
7778match fn {
79 type_ => || ffi::gtk_box_layout_get_type(),
80 }
81}
8283impl 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")]
92pub fn new(orientation: Orientation) -> BoxLayout {
93assert_initialized_main_thread!();
94unsafe {
95LayoutManager::from_glib_full(ffi::gtk_box_layout_new(orientation.into_glib()))
96 .unsafe_cast()
97 }
98 }
99100// 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.
104pub fn builder() -> BoxLayoutBuilder {
105BoxLayoutBuilder::new()
106 }
107108/// 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")]
119pub fn baseline_child(&self) -> i32 {
120unsafe { ffi::gtk_box_layout_get_baseline_child(self.to_glib_none().0) }
121 }
122123/// 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")]
131pub fn baseline_position(&self) -> BaselinePosition {
132unsafe {
133from_glib(ffi::gtk_box_layout_get_baseline_position(
134self.to_glib_none().0,
135 ))
136 }
137 }
138139/// 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")]
147pub fn is_homogeneous(&self) -> bool {
148unsafe { from_glib(ffi::gtk_box_layout_get_homogeneous(self.to_glib_none().0)) }
149 }
150151/// 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")]
158pub fn spacing(&self) -> u32 {
159unsafe { ffi::gtk_box_layout_get_spacing(self.to_glib_none().0) }
160 }
161162/// 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")]
170pub fn set_baseline_child(&self, child: i32) {
171unsafe {
172ffi::gtk_box_layout_set_baseline_child(self.to_glib_none().0, child);
173 }
174 }
175176/// 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")]
187pub fn set_baseline_position(&self, position: BaselinePosition) {
188unsafe {
189ffi::gtk_box_layout_set_baseline_position(self.to_glib_none().0, position.into_glib());
190 }
191 }
192193/// 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")]
199pub fn set_homogeneous(&self, homogeneous: bool) {
200unsafe {
201ffi::gtk_box_layout_set_homogeneous(self.to_glib_none().0, homogeneous.into_glib());
202 }
203 }
204205/// 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")]
210pub fn set_spacing(&self, spacing: u32) {
211unsafe {
212ffi::gtk_box_layout_set_spacing(self.to_glib_none().0, spacing);
213 }
214 }
215216#[cfg(feature = "v4_12")]
217 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
218 #[doc(alias = "baseline-child")]
219pub fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
220unsafe 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 ) {
225let f: &F = &*(fas *const F);
226f(&from_glib_borrow(this))
227 }
228unsafe {
229let f: Box_<F> = Box_::new(f);
230connect_raw(
231self.as_ptr() as *mut _,
232c"notify::baseline-child".as_ptr() as *const _,
233Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
234notify_baseline_child_trampoline::<F> as *const (),
235 )),
236Box_::into_raw(f),
237 )
238 }
239 }
240241#[doc(alias = "baseline-position")]
242pub fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(
243&self,
244 f: F,
245 ) -> SignalHandlerId {
246unsafe 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 ) {
251let f: &F = &*(fas *const F);
252f(&from_glib_borrow(this))
253 }
254unsafe {
255let f: Box_<F> = Box_::new(f);
256connect_raw(
257self.as_ptr() as *mut _,
258c"notify::baseline-position".as_ptr() as *const _,
259Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
260notify_baseline_position_trampoline::<F> as *const (),
261 )),
262Box_::into_raw(f),
263 )
264 }
265 }
266267#[doc(alias = "homogeneous")]
268pub fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
269unsafe 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 ) {
274let f: &F = &*(fas *const F);
275f(&from_glib_borrow(this))
276 }
277unsafe {
278let f: Box_<F> = Box_::new(f);
279connect_raw(
280self.as_ptr() as *mut _,
281c"notify::homogeneous".as_ptr() as *const _,
282Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
283notify_homogeneous_trampoline::<F> as *const (),
284 )),
285Box_::into_raw(f),
286 )
287 }
288 }
289290#[doc(alias = "spacing")]
291pub fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
292unsafe 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 ) {
297let f: &F = &*(fas *const F);
298f(&from_glib_borrow(this))
299 }
300unsafe {
301let f: Box_<F> = Box_::new(f);
302connect_raw(
303self.as_ptr() as *mut _,
304c"notify::spacing".as_ptr() as *const _,
305Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
306notify_spacing_trampoline::<F> as *const (),
307 )),
308Box_::into_raw(f),
309 )
310 }
311 }
312}
313314impl Defaultfor BoxLayout {
315fn default() -> Self {
316 glib::object::Object::new::<Self>()
317 }
318}
319320// 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}
328329impl BoxLayoutBuilder {
330fn new() -> Self {
331Self {
332 builder: glib::object::Object::builder(),
333 }
334 }
335336/// 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")))]
344pub fn baseline_child(self, baseline_child: i32) -> Self {
345Self {
346 builder: self.builder.property("baseline-child", baseline_child),
347 }
348 }
349350/// 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.
355pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
356Self {
357 builder: self358.builder
359 .property("baseline-position", baseline_position),
360 }
361 }
362363/// Whether the box layout should distribute the available space
364 /// equally among the children.
365pub fn homogeneous(self, homogeneous: bool) -> Self {
366Self {
367 builder: self.builder.property("homogeneous", homogeneous),
368 }
369 }
370371/// The space to put between the children.
372pub fn spacing(self, spacing: i32) -> Self {
373Self {
374 builder: self.builder.property("spacing", spacing),
375 }
376 }
377378/// The orientation of the orientable.
379pub fn orientation(self, orientation: Orientation) -> Self {
380Self {
381 builder: self.builder.property("orientation", orientation),
382 }
383 }
384385// 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"]
388pub fn build(self) -> BoxLayout {
389assert_initialized_main_thread!();
390self.builder.build()
391 }
392}