[go: up one dir, main page]

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    #[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            let f: &F = &*(f as *const F);
117            f(&from_glib_borrow(this))
118        }
119        unsafe {
120            let f: Box_<F> = Box_::new(f);
121            connect_raw(
122                self.as_ptr() as *mut _,
123                c"notify::baseline-child".as_ptr() as *const _,
124                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
125                    notify_baseline_child_trampoline::<F> as *const (),
126                )),
127                Box_::into_raw(f),
128            )
129        }
130    }
131
132    #[doc(alias = "baseline-position")]
133    pub fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(
134        &self,
135        f: F,
136    ) -> SignalHandlerId {
137        unsafe extern "C" fn notify_baseline_position_trampoline<F: Fn(&BoxLayout) + 'static>(
138            this: *mut ffi::GtkBoxLayout,
139            _param_spec: glib::ffi::gpointer,
140            f: glib::ffi::gpointer,
141        ) {
142            let f: &F = &*(f as *const F);
143            f(&from_glib_borrow(this))
144        }
145        unsafe {
146            let f: Box_<F> = Box_::new(f);
147            connect_raw(
148                self.as_ptr() as *mut _,
149                c"notify::baseline-position".as_ptr() as *const _,
150                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
151                    notify_baseline_position_trampoline::<F> as *const (),
152                )),
153                Box_::into_raw(f),
154            )
155        }
156    }
157
158    #[doc(alias = "homogeneous")]
159    pub fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
160        unsafe extern "C" fn notify_homogeneous_trampoline<F: Fn(&BoxLayout) + 'static>(
161            this: *mut ffi::GtkBoxLayout,
162            _param_spec: glib::ffi::gpointer,
163            f: glib::ffi::gpointer,
164        ) {
165            let f: &F = &*(f as *const F);
166            f(&from_glib_borrow(this))
167        }
168        unsafe {
169            let f: Box_<F> = Box_::new(f);
170            connect_raw(
171                self.as_ptr() as *mut _,
172                c"notify::homogeneous".as_ptr() as *const _,
173                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
174                    notify_homogeneous_trampoline::<F> as *const (),
175                )),
176                Box_::into_raw(f),
177            )
178        }
179    }
180
181    #[doc(alias = "spacing")]
182    pub fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
183        unsafe extern "C" fn notify_spacing_trampoline<F: Fn(&BoxLayout) + 'static>(
184            this: *mut ffi::GtkBoxLayout,
185            _param_spec: glib::ffi::gpointer,
186            f: glib::ffi::gpointer,
187        ) {
188            let f: &F = &*(f as *const F);
189            f(&from_glib_borrow(this))
190        }
191        unsafe {
192            let f: Box_<F> = Box_::new(f);
193            connect_raw(
194                self.as_ptr() as *mut _,
195                c"notify::spacing".as_ptr() as *const _,
196                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
197                    notify_spacing_trampoline::<F> as *const (),
198                )),
199                Box_::into_raw(f),
200            )
201        }
202    }
203}
204
205impl Default for BoxLayout {
206    fn default() -> Self {
207        glib::object::Object::new::<Self>()
208    }
209}
210
211// rustdoc-stripper-ignore-next
212/// A [builder-pattern] type to construct [`BoxLayout`] objects.
213///
214/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
215#[must_use = "The builder must be built to be used"]
216pub struct BoxLayoutBuilder {
217    builder: glib::object::ObjectBuilder<'static, BoxLayout>,
218}
219
220impl BoxLayoutBuilder {
221    fn new() -> Self {
222        Self {
223            builder: glib::object::Object::builder(),
224        }
225    }
226
227    #[cfg(feature = "v4_12")]
228    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
229    pub fn baseline_child(self, baseline_child: i32) -> Self {
230        Self {
231            builder: self.builder.property("baseline-child", baseline_child),
232        }
233    }
234
235    pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
236        Self {
237            builder: self
238                .builder
239                .property("baseline-position", baseline_position),
240        }
241    }
242
243    pub fn homogeneous(self, homogeneous: bool) -> Self {
244        Self {
245            builder: self.builder.property("homogeneous", homogeneous),
246        }
247    }
248
249    pub fn spacing(self, spacing: i32) -> Self {
250        Self {
251            builder: self.builder.property("spacing", spacing),
252        }
253    }
254
255    pub fn orientation(self, orientation: Orientation) -> Self {
256        Self {
257            builder: self.builder.property("orientation", orientation),
258        }
259    }
260
261    // rustdoc-stripper-ignore-next
262    /// Build the [`BoxLayout`].
263    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
264    pub fn build(self) -> BoxLayout {
265        assert_initialized_main_thread!();
266        self.builder.build()
267    }
268}