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    #[doc(alias = "GtkBoxLayout")]
15    pub struct BoxLayout(Object<ffi::GtkBoxLayout, ffi::GtkBoxLayoutClass>) @extends LayoutManager, @implements Orientable;
16
17    match fn {
18        type_ => || ffi::gtk_box_layout_get_type(),
19    }
20}
21
22impl BoxLayout {
23    #[doc(alias = "gtk_box_layout_new")]
24    pub fn new(orientation: Orientation) -> BoxLayout {
25        assert_initialized_main_thread!();
26        unsafe {
27            LayoutManager::from_glib_full(ffi::gtk_box_layout_new(orientation.into_glib()))
28                .unsafe_cast()
29        }
30    }
31
32    // rustdoc-stripper-ignore-next
33    /// Creates a new builder-pattern struct instance to construct [`BoxLayout`] objects.
34    ///
35    /// This method returns an instance of [`BoxLayoutBuilder`](crate::builders::BoxLayoutBuilder) which can be used to create [`BoxLayout`] objects.
36    pub fn builder() -> BoxLayoutBuilder {
37        BoxLayoutBuilder::new()
38    }
39
40    #[cfg(feature = "v4_12")]
41    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
42    #[doc(alias = "gtk_box_layout_get_baseline_child")]
43    #[doc(alias = "get_baseline_child")]
44    #[doc(alias = "baseline-child")]
45    pub fn baseline_child(&self) -> i32 {
46        unsafe { ffi::gtk_box_layout_get_baseline_child(self.to_glib_none().0) }
47    }
48
49    #[doc(alias = "gtk_box_layout_get_baseline_position")]
50    #[doc(alias = "get_baseline_position")]
51    #[doc(alias = "baseline-position")]
52    pub fn baseline_position(&self) -> BaselinePosition {
53        unsafe {
54            from_glib(ffi::gtk_box_layout_get_baseline_position(
55                self.to_glib_none().0,
56            ))
57        }
58    }
59
60    #[doc(alias = "gtk_box_layout_get_homogeneous")]
61    #[doc(alias = "get_homogeneous")]
62    #[doc(alias = "homogeneous")]
63    pub fn is_homogeneous(&self) -> bool {
64        unsafe { from_glib(ffi::gtk_box_layout_get_homogeneous(self.to_glib_none().0)) }
65    }
66
67    #[doc(alias = "gtk_box_layout_get_spacing")]
68    #[doc(alias = "get_spacing")]
69    pub fn spacing(&self) -> u32 {
70        unsafe { ffi::gtk_box_layout_get_spacing(self.to_glib_none().0) }
71    }
72
73    #[cfg(feature = "v4_12")]
74    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
75    #[doc(alias = "gtk_box_layout_set_baseline_child")]
76    #[doc(alias = "baseline-child")]
77    pub fn set_baseline_child(&self, child: i32) {
78        unsafe {
79            ffi::gtk_box_layout_set_baseline_child(self.to_glib_none().0, child);
80        }
81    }
82
83    #[doc(alias = "gtk_box_layout_set_baseline_position")]
84    #[doc(alias = "baseline-position")]
85    pub fn set_baseline_position(&self, position: BaselinePosition) {
86        unsafe {
87            ffi::gtk_box_layout_set_baseline_position(self.to_glib_none().0, position.into_glib());
88        }
89    }
90
91    #[doc(alias = "gtk_box_layout_set_homogeneous")]
92    #[doc(alias = "homogeneous")]
93    pub fn set_homogeneous(&self, homogeneous: bool) {
94        unsafe {
95            ffi::gtk_box_layout_set_homogeneous(self.to_glib_none().0, homogeneous.into_glib());
96        }
97    }
98
99    #[doc(alias = "gtk_box_layout_set_spacing")]
100    #[doc(alias = "spacing")]
101    pub fn set_spacing(&self, spacing: u32) {
102        unsafe {
103            ffi::gtk_box_layout_set_spacing(self.to_glib_none().0, spacing);
104        }
105    }
106
107    #[cfg(feature = "v4_12")]
108    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
109    #[doc(alias = "baseline-child")]
110    pub fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
111        unsafe extern "C" fn notify_baseline_child_trampoline<F: Fn(&BoxLayout) + 'static>(
112            this: *mut ffi::GtkBoxLayout,
113            _param_spec: glib::ffi::gpointer,
114            f: glib::ffi::gpointer,
115        ) {
116            unsafe {
117                let f: &F = &*(f as *const F);
118                f(&from_glib_borrow(this))
119            }
120        }
121        unsafe {
122            let f: Box_<F> = Box_::new(f);
123            connect_raw(
124                self.as_ptr() as *mut _,
125                c"notify::baseline-child".as_ptr(),
126                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
127                    notify_baseline_child_trampoline::<F> as *const (),
128                )),
129                Box_::into_raw(f),
130            )
131        }
132    }
133
134    #[doc(alias = "baseline-position")]
135    pub fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(
136        &self,
137        f: F,
138    ) -> SignalHandlerId {
139        unsafe extern "C" fn notify_baseline_position_trampoline<F: Fn(&BoxLayout) + 'static>(
140            this: *mut ffi::GtkBoxLayout,
141            _param_spec: glib::ffi::gpointer,
142            f: glib::ffi::gpointer,
143        ) {
144            unsafe {
145                let f: &F = &*(f as *const F);
146                f(&from_glib_borrow(this))
147            }
148        }
149        unsafe {
150            let f: Box_<F> = Box_::new(f);
151            connect_raw(
152                self.as_ptr() as *mut _,
153                c"notify::baseline-position".as_ptr(),
154                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
155                    notify_baseline_position_trampoline::<F> as *const (),
156                )),
157                Box_::into_raw(f),
158            )
159        }
160    }
161
162    #[doc(alias = "homogeneous")]
163    pub fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
164        unsafe extern "C" fn notify_homogeneous_trampoline<F: Fn(&BoxLayout) + 'static>(
165            this: *mut ffi::GtkBoxLayout,
166            _param_spec: glib::ffi::gpointer,
167            f: glib::ffi::gpointer,
168        ) {
169            unsafe {
170                let f: &F = &*(f as *const F);
171                f(&from_glib_borrow(this))
172            }
173        }
174        unsafe {
175            let f: Box_<F> = Box_::new(f);
176            connect_raw(
177                self.as_ptr() as *mut _,
178                c"notify::homogeneous".as_ptr(),
179                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
180                    notify_homogeneous_trampoline::<F> as *const (),
181                )),
182                Box_::into_raw(f),
183            )
184        }
185    }
186
187    #[doc(alias = "spacing")]
188    pub fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
189        unsafe extern "C" fn notify_spacing_trampoline<F: Fn(&BoxLayout) + 'static>(
190            this: *mut ffi::GtkBoxLayout,
191            _param_spec: glib::ffi::gpointer,
192            f: glib::ffi::gpointer,
193        ) {
194            unsafe {
195                let f: &F = &*(f as *const F);
196                f(&from_glib_borrow(this))
197            }
198        }
199        unsafe {
200            let f: Box_<F> = Box_::new(f);
201            connect_raw(
202                self.as_ptr() as *mut _,
203                c"notify::spacing".as_ptr(),
204                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
205                    notify_spacing_trampoline::<F> as *const (),
206                )),
207                Box_::into_raw(f),
208            )
209        }
210    }
211}
212
213impl Default for BoxLayout {
214    fn default() -> Self {
215        glib::object::Object::new::<Self>()
216    }
217}
218
219// rustdoc-stripper-ignore-next
220/// A [builder-pattern] type to construct [`BoxLayout`] objects.
221///
222/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
223#[must_use = "The builder must be built to be used"]
224pub struct BoxLayoutBuilder {
225    builder: glib::object::ObjectBuilder<'static, BoxLayout>,
226}
227
228impl BoxLayoutBuilder {
229    fn new() -> Self {
230        Self {
231            builder: glib::object::Object::builder(),
232        }
233    }
234
235    #[cfg(feature = "v4_12")]
236    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
237    pub fn baseline_child(self, baseline_child: i32) -> Self {
238        Self {
239            builder: self.builder.property("baseline-child", baseline_child),
240        }
241    }
242
243    pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
244        Self {
245            builder: self
246                .builder
247                .property("baseline-position", baseline_position),
248        }
249    }
250
251    pub fn homogeneous(self, homogeneous: bool) -> Self {
252        Self {
253            builder: self.builder.property("homogeneous", homogeneous),
254        }
255    }
256
257    pub fn spacing(self, spacing: i32) -> Self {
258        Self {
259            builder: self.builder.property("spacing", spacing),
260        }
261    }
262
263    pub fn orientation(self, orientation: Orientation) -> Self {
264        Self {
265            builder: self.builder.property("orientation", orientation),
266        }
267    }
268
269    // rustdoc-stripper-ignore-next
270    /// Build the [`BoxLayout`].
271    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
272    pub fn build(self) -> BoxLayout {
273        assert_initialized_main_thread!();
274        self.builder.build()
275    }
276}