1use 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")]
76 pub struct BoxLayout(Object<ffi::GtkBoxLayout, ffi::GtkBoxLayoutClass>) @extends LayoutManager, @implements Orientable;
77
78 match fn {
79 type_ => || ffi::gtk_box_layout_get_type(),
80 }
81}
82
83impl BoxLayout {
84 #[doc(alias = "gtk_box_layout_new")]
92 pub fn new(orientation: Orientation) -> BoxLayout {
93 assert_initialized_main_thread!();
94 unsafe {
95 LayoutManager::from_glib_full(ffi::gtk_box_layout_new(orientation.into_glib()))
96 .unsafe_cast()
97 }
98 }
99
100 pub fn builder() -> BoxLayoutBuilder {
105 BoxLayoutBuilder::new()
106 }
107
108 #[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")]
119 pub fn baseline_child(&self) -> i32 {
120 unsafe { ffi::gtk_box_layout_get_baseline_child(self.to_glib_none().0) }
121 }
122
123 #[doc(alias = "gtk_box_layout_get_baseline_position")]
129 #[doc(alias = "get_baseline_position")]
130 #[doc(alias = "baseline-position")]
131 pub fn baseline_position(&self) -> BaselinePosition {
132 unsafe {
133 from_glib(ffi::gtk_box_layout_get_baseline_position(
134 self.to_glib_none().0,
135 ))
136 }
137 }
138
139 #[doc(alias = "gtk_box_layout_get_homogeneous")]
145 #[doc(alias = "get_homogeneous")]
146 #[doc(alias = "homogeneous")]
147 pub fn is_homogeneous(&self) -> bool {
148 unsafe { from_glib(ffi::gtk_box_layout_get_homogeneous(self.to_glib_none().0)) }
149 }
150
151 #[doc(alias = "gtk_box_layout_get_spacing")]
157 #[doc(alias = "get_spacing")]
158 pub fn spacing(&self) -> u32 {
159 unsafe { ffi::gtk_box_layout_get_spacing(self.to_glib_none().0) }
160 }
161
162 #[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")]
170 pub fn set_baseline_child(&self, child: i32) {
171 unsafe {
172 ffi::gtk_box_layout_set_baseline_child(self.to_glib_none().0, child);
173 }
174 }
175
176 #[doc(alias = "gtk_box_layout_set_baseline_position")]
186 #[doc(alias = "baseline-position")]
187 pub fn set_baseline_position(&self, position: BaselinePosition) {
188 unsafe {
189 ffi::gtk_box_layout_set_baseline_position(self.to_glib_none().0, position.into_glib());
190 }
191 }
192
193 #[doc(alias = "gtk_box_layout_set_homogeneous")]
198 #[doc(alias = "homogeneous")]
199 pub fn set_homogeneous(&self, homogeneous: bool) {
200 unsafe {
201 ffi::gtk_box_layout_set_homogeneous(self.to_glib_none().0, homogeneous.into_glib());
202 }
203 }
204
205 #[doc(alias = "gtk_box_layout_set_spacing")]
209 #[doc(alias = "spacing")]
210 pub fn set_spacing(&self, spacing: u32) {
211 unsafe {
212 ffi::gtk_box_layout_set_spacing(self.to_glib_none().0, spacing);
213 }
214 }
215
216 #[cfg(feature = "v4_12")]
217 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
218 #[doc(alias = "baseline-child")]
219 pub fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
220 unsafe 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 ) {
225 unsafe {
226 let f: &F = &*(f as *const F);
227 f(&from_glib_borrow(this))
228 }
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"notify::baseline-child".as_ptr() as *const _,
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 notify_baseline_child_trampoline::<F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242
243 #[doc(alias = "baseline-position")]
244 pub fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(
245 &self,
246 f: F,
247 ) -> SignalHandlerId {
248 unsafe extern "C" fn notify_baseline_position_trampoline<F: Fn(&BoxLayout) + 'static>(
249 this: *mut ffi::GtkBoxLayout,
250 _param_spec: glib::ffi::gpointer,
251 f: glib::ffi::gpointer,
252 ) {
253 unsafe {
254 let f: &F = &*(f as *const F);
255 f(&from_glib_borrow(this))
256 }
257 }
258 unsafe {
259 let f: Box_<F> = Box_::new(f);
260 connect_raw(
261 self.as_ptr() as *mut _,
262 c"notify::baseline-position".as_ptr() as *const _,
263 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
264 notify_baseline_position_trampoline::<F> as *const (),
265 )),
266 Box_::into_raw(f),
267 )
268 }
269 }
270
271 #[doc(alias = "homogeneous")]
272 pub fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
273 unsafe extern "C" fn notify_homogeneous_trampoline<F: Fn(&BoxLayout) + 'static>(
274 this: *mut ffi::GtkBoxLayout,
275 _param_spec: glib::ffi::gpointer,
276 f: glib::ffi::gpointer,
277 ) {
278 unsafe {
279 let f: &F = &*(f as *const F);
280 f(&from_glib_borrow(this))
281 }
282 }
283 unsafe {
284 let f: Box_<F> = Box_::new(f);
285 connect_raw(
286 self.as_ptr() as *mut _,
287 c"notify::homogeneous".as_ptr() as *const _,
288 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
289 notify_homogeneous_trampoline::<F> as *const (),
290 )),
291 Box_::into_raw(f),
292 )
293 }
294 }
295
296 #[doc(alias = "spacing")]
297 pub fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
298 unsafe extern "C" fn notify_spacing_trampoline<F: Fn(&BoxLayout) + 'static>(
299 this: *mut ffi::GtkBoxLayout,
300 _param_spec: glib::ffi::gpointer,
301 f: glib::ffi::gpointer,
302 ) {
303 unsafe {
304 let f: &F = &*(f as *const F);
305 f(&from_glib_borrow(this))
306 }
307 }
308 unsafe {
309 let f: Box_<F> = Box_::new(f);
310 connect_raw(
311 self.as_ptr() as *mut _,
312 c"notify::spacing".as_ptr() as *const _,
313 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
314 notify_spacing_trampoline::<F> as *const (),
315 )),
316 Box_::into_raw(f),
317 )
318 }
319 }
320}
321
322impl Default for BoxLayout {
323 fn default() -> Self {
324 glib::object::Object::new::<Self>()
325 }
326}
327
328#[must_use = "The builder must be built to be used"]
333pub struct BoxLayoutBuilder {
334 builder: glib::object::ObjectBuilder<'static, BoxLayout>,
335}
336
337impl BoxLayoutBuilder {
338 fn new() -> Self {
339 Self {
340 builder: glib::object::Object::builder(),
341 }
342 }
343
344 #[cfg(feature = "v4_12")]
351 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
352 pub fn baseline_child(self, baseline_child: i32) -> Self {
353 Self {
354 builder: self.builder.property("baseline-child", baseline_child),
355 }
356 }
357
358 pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
364 Self {
365 builder: self
366 .builder
367 .property("baseline-position", baseline_position),
368 }
369 }
370
371 pub fn homogeneous(self, homogeneous: bool) -> Self {
374 Self {
375 builder: self.builder.property("homogeneous", homogeneous),
376 }
377 }
378
379 pub fn spacing(self, spacing: i32) -> Self {
381 Self {
382 builder: self.builder.property("spacing", spacing),
383 }
384 }
385
386 pub fn orientation(self, orientation: Orientation) -> Self {
388 Self {
389 builder: self.builder.property("orientation", orientation),
390 }
391 }
392
393 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
396 pub fn build(self) -> BoxLayout {
397 assert_initialized_main_thread!();
398 self.builder.build()
399 }
400}