1use crate::{
6 Align, BaselinePosition, Buildable, Container, Orientable, Orientation, PackType, ResizeMode,
7 Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::{boxed::Box as Box_, fmt, mem, mem::transmute};
15
16glib::wrapper! {
17 #[doc(alias = "GtkBox")]
18 pub struct Box(Object<ffi::GtkBox, ffi::GtkBoxClass>) @extends Container, Widget, @implements Buildable, Orientable;
19
20 match fn {
21 type_ => || ffi::gtk_box_get_type(),
22 }
23}
24
25impl Box {
26 pub const NONE: Option<&'static Box> = None;
27
28 #[doc(alias = "gtk_box_new")]
29 pub fn new(orientation: Orientation, spacing: i32) -> Box {
30 assert_initialized_main_thread!();
31 unsafe {
32 Widget::from_glib_none(ffi::gtk_box_new(orientation.into_glib(), spacing)).unsafe_cast()
33 }
34 }
35
36 pub fn builder() -> BoxBuilder {
41 BoxBuilder::new()
42 }
43}
44
45impl Default for Box {
46 fn default() -> Self {
47 glib::object::Object::new::<Self>()
48 }
49}
50
51#[must_use = "The builder must be built to be used"]
56pub struct BoxBuilder {
57 builder: glib::object::ObjectBuilder<'static, Box>,
58}
59
60impl BoxBuilder {
61 fn new() -> Self {
62 Self {
63 builder: glib::object::Object::builder(),
64 }
65 }
66
67 pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
68 Self {
69 builder: self
70 .builder
71 .property("baseline-position", baseline_position),
72 }
73 }
74
75 pub fn homogeneous(self, homogeneous: bool) -> Self {
76 Self {
77 builder: self.builder.property("homogeneous", homogeneous),
78 }
79 }
80
81 pub fn spacing(self, spacing: i32) -> Self {
82 Self {
83 builder: self.builder.property("spacing", spacing),
84 }
85 }
86
87 pub fn border_width(self, border_width: u32) -> Self {
88 Self {
89 builder: self.builder.property("border-width", border_width),
90 }
91 }
92
93 pub fn child(self, child: &impl IsA<Widget>) -> Self {
94 Self {
95 builder: self.builder.property("child", child.clone().upcast()),
96 }
97 }
98
99 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
100 Self {
101 builder: self.builder.property("resize-mode", resize_mode),
102 }
103 }
104
105 pub fn app_paintable(self, app_paintable: bool) -> Self {
106 Self {
107 builder: self.builder.property("app-paintable", app_paintable),
108 }
109 }
110
111 pub fn can_default(self, can_default: bool) -> Self {
112 Self {
113 builder: self.builder.property("can-default", can_default),
114 }
115 }
116
117 pub fn can_focus(self, can_focus: bool) -> Self {
118 Self {
119 builder: self.builder.property("can-focus", can_focus),
120 }
121 }
122
123 pub fn events(self, events: gdk::EventMask) -> Self {
124 Self {
125 builder: self.builder.property("events", events),
126 }
127 }
128
129 pub fn expand(self, expand: bool) -> Self {
130 Self {
131 builder: self.builder.property("expand", expand),
132 }
133 }
134
135 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
136 Self {
137 builder: self.builder.property("focus-on-click", focus_on_click),
138 }
139 }
140
141 pub fn halign(self, halign: Align) -> Self {
142 Self {
143 builder: self.builder.property("halign", halign),
144 }
145 }
146
147 pub fn has_default(self, has_default: bool) -> Self {
148 Self {
149 builder: self.builder.property("has-default", has_default),
150 }
151 }
152
153 pub fn has_focus(self, has_focus: bool) -> Self {
154 Self {
155 builder: self.builder.property("has-focus", has_focus),
156 }
157 }
158
159 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
160 Self {
161 builder: self.builder.property("has-tooltip", has_tooltip),
162 }
163 }
164
165 pub fn height_request(self, height_request: i32) -> Self {
166 Self {
167 builder: self.builder.property("height-request", height_request),
168 }
169 }
170
171 pub fn hexpand(self, hexpand: bool) -> Self {
172 Self {
173 builder: self.builder.property("hexpand", hexpand),
174 }
175 }
176
177 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
178 Self {
179 builder: self.builder.property("hexpand-set", hexpand_set),
180 }
181 }
182
183 pub fn is_focus(self, is_focus: bool) -> Self {
184 Self {
185 builder: self.builder.property("is-focus", is_focus),
186 }
187 }
188
189 pub fn margin(self, margin: i32) -> Self {
190 Self {
191 builder: self.builder.property("margin", margin),
192 }
193 }
194
195 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
196 Self {
197 builder: self.builder.property("margin-bottom", margin_bottom),
198 }
199 }
200
201 pub fn margin_end(self, margin_end: i32) -> Self {
202 Self {
203 builder: self.builder.property("margin-end", margin_end),
204 }
205 }
206
207 pub fn margin_start(self, margin_start: i32) -> Self {
208 Self {
209 builder: self.builder.property("margin-start", margin_start),
210 }
211 }
212
213 pub fn margin_top(self, margin_top: i32) -> Self {
214 Self {
215 builder: self.builder.property("margin-top", margin_top),
216 }
217 }
218
219 pub fn name(self, name: impl Into<glib::GString>) -> Self {
220 Self {
221 builder: self.builder.property("name", name.into()),
222 }
223 }
224
225 pub fn no_show_all(self, no_show_all: bool) -> Self {
226 Self {
227 builder: self.builder.property("no-show-all", no_show_all),
228 }
229 }
230
231 pub fn opacity(self, opacity: f64) -> Self {
232 Self {
233 builder: self.builder.property("opacity", opacity),
234 }
235 }
236
237 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
238 Self {
239 builder: self.builder.property("parent", parent.clone().upcast()),
240 }
241 }
242
243 pub fn receives_default(self, receives_default: bool) -> Self {
244 Self {
245 builder: self.builder.property("receives-default", receives_default),
246 }
247 }
248
249 pub fn sensitive(self, sensitive: bool) -> Self {
250 Self {
251 builder: self.builder.property("sensitive", sensitive),
252 }
253 }
254
255 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
256 Self {
257 builder: self
258 .builder
259 .property("tooltip-markup", tooltip_markup.into()),
260 }
261 }
262
263 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
264 Self {
265 builder: self.builder.property("tooltip-text", tooltip_text.into()),
266 }
267 }
268
269 pub fn valign(self, valign: Align) -> Self {
270 Self {
271 builder: self.builder.property("valign", valign),
272 }
273 }
274
275 pub fn vexpand(self, vexpand: bool) -> Self {
276 Self {
277 builder: self.builder.property("vexpand", vexpand),
278 }
279 }
280
281 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
282 Self {
283 builder: self.builder.property("vexpand-set", vexpand_set),
284 }
285 }
286
287 pub fn visible(self, visible: bool) -> Self {
288 Self {
289 builder: self.builder.property("visible", visible),
290 }
291 }
292
293 pub fn width_request(self, width_request: i32) -> Self {
294 Self {
295 builder: self.builder.property("width-request", width_request),
296 }
297 }
298
299 pub fn orientation(self, orientation: Orientation) -> Self {
300 Self {
301 builder: self.builder.property("orientation", orientation),
302 }
303 }
304
305 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
308 pub fn build(self) -> Box {
309 self.builder.build()
310 }
311}
312
313mod sealed {
314 pub trait Sealed {}
315 impl<T: super::IsA<super::Box>> Sealed for T {}
316}
317
318pub trait BoxExt: IsA<Box> + sealed::Sealed + 'static {
319 #[doc(alias = "gtk_box_get_baseline_position")]
320 #[doc(alias = "get_baseline_position")]
321 fn baseline_position(&self) -> BaselinePosition {
322 unsafe {
323 from_glib(ffi::gtk_box_get_baseline_position(
324 self.as_ref().to_glib_none().0,
325 ))
326 }
327 }
328
329 #[doc(alias = "gtk_box_get_center_widget")]
330 #[doc(alias = "get_center_widget")]
331 fn center_widget(&self) -> Option<Widget> {
332 unsafe {
333 from_glib_none(ffi::gtk_box_get_center_widget(
334 self.as_ref().to_glib_none().0,
335 ))
336 }
337 }
338
339 #[doc(alias = "gtk_box_get_homogeneous")]
340 #[doc(alias = "get_homogeneous")]
341 fn is_homogeneous(&self) -> bool {
342 unsafe { from_glib(ffi::gtk_box_get_homogeneous(self.as_ref().to_glib_none().0)) }
343 }
344
345 #[doc(alias = "gtk_box_get_spacing")]
346 #[doc(alias = "get_spacing")]
347 fn spacing(&self) -> i32 {
348 unsafe { ffi::gtk_box_get_spacing(self.as_ref().to_glib_none().0) }
349 }
350
351 #[doc(alias = "gtk_box_pack_end")]
352 fn pack_end(&self, child: &impl IsA<Widget>, expand: bool, fill: bool, padding: u32) {
353 unsafe {
354 ffi::gtk_box_pack_end(
355 self.as_ref().to_glib_none().0,
356 child.as_ref().to_glib_none().0,
357 expand.into_glib(),
358 fill.into_glib(),
359 padding,
360 );
361 }
362 }
363
364 #[doc(alias = "gtk_box_pack_start")]
365 fn pack_start(&self, child: &impl IsA<Widget>, expand: bool, fill: bool, padding: u32) {
366 unsafe {
367 ffi::gtk_box_pack_start(
368 self.as_ref().to_glib_none().0,
369 child.as_ref().to_glib_none().0,
370 expand.into_glib(),
371 fill.into_glib(),
372 padding,
373 );
374 }
375 }
376
377 #[doc(alias = "gtk_box_query_child_packing")]
378 fn query_child_packing(&self, child: &impl IsA<Widget>) -> (bool, bool, u32, PackType) {
379 unsafe {
380 let mut expand = mem::MaybeUninit::uninit();
381 let mut fill = mem::MaybeUninit::uninit();
382 let mut padding = mem::MaybeUninit::uninit();
383 let mut pack_type = mem::MaybeUninit::uninit();
384 ffi::gtk_box_query_child_packing(
385 self.as_ref().to_glib_none().0,
386 child.as_ref().to_glib_none().0,
387 expand.as_mut_ptr(),
388 fill.as_mut_ptr(),
389 padding.as_mut_ptr(),
390 pack_type.as_mut_ptr(),
391 );
392 (
393 from_glib(expand.assume_init()),
394 from_glib(fill.assume_init()),
395 padding.assume_init(),
396 from_glib(pack_type.assume_init()),
397 )
398 }
399 }
400
401 #[doc(alias = "gtk_box_reorder_child")]
402 fn reorder_child(&self, child: &impl IsA<Widget>, position: i32) {
403 unsafe {
404 ffi::gtk_box_reorder_child(
405 self.as_ref().to_glib_none().0,
406 child.as_ref().to_glib_none().0,
407 position,
408 );
409 }
410 }
411
412 #[doc(alias = "gtk_box_set_baseline_position")]
413 fn set_baseline_position(&self, position: BaselinePosition) {
414 unsafe {
415 ffi::gtk_box_set_baseline_position(
416 self.as_ref().to_glib_none().0,
417 position.into_glib(),
418 );
419 }
420 }
421
422 #[doc(alias = "gtk_box_set_center_widget")]
423 fn set_center_widget(&self, widget: Option<&impl IsA<Widget>>) {
424 unsafe {
425 ffi::gtk_box_set_center_widget(
426 self.as_ref().to_glib_none().0,
427 widget.map(|p| p.as_ref()).to_glib_none().0,
428 );
429 }
430 }
431
432 #[doc(alias = "gtk_box_set_child_packing")]
433 fn set_child_packing(
434 &self,
435 child: &impl IsA<Widget>,
436 expand: bool,
437 fill: bool,
438 padding: u32,
439 pack_type: PackType,
440 ) {
441 unsafe {
442 ffi::gtk_box_set_child_packing(
443 self.as_ref().to_glib_none().0,
444 child.as_ref().to_glib_none().0,
445 expand.into_glib(),
446 fill.into_glib(),
447 padding,
448 pack_type.into_glib(),
449 );
450 }
451 }
452
453 #[doc(alias = "gtk_box_set_homogeneous")]
454 fn set_homogeneous(&self, homogeneous: bool) {
455 unsafe {
456 ffi::gtk_box_set_homogeneous(self.as_ref().to_glib_none().0, homogeneous.into_glib());
457 }
458 }
459
460 #[doc(alias = "gtk_box_set_spacing")]
461 fn set_spacing(&self, spacing: i32) {
462 unsafe {
463 ffi::gtk_box_set_spacing(self.as_ref().to_glib_none().0, spacing);
464 }
465 }
466
467 fn child_expands<T: IsA<crate::Widget>>(&self, item: &T) -> bool {
468 crate::prelude::ContainerExtManual::child_property(
469 self.as_ref(),
470 &item.clone().upcast(),
471 "expand",
472 )
473 }
474
475 fn set_child_expand<T: IsA<crate::Widget>>(&self, item: &T, expand: bool) {
476 crate::prelude::ContainerExtManual::child_set_property(
477 self.as_ref(),
478 &item.clone().upcast(),
479 "expand",
480 &expand,
481 )
482 }
483
484 fn child_fills<T: IsA<crate::Widget>>(&self, item: &T) -> bool {
485 crate::prelude::ContainerExtManual::child_property(
486 self.as_ref(),
487 &item.clone().upcast(),
488 "fill",
489 )
490 }
491
492 fn set_child_fill<T: IsA<crate::Widget>>(&self, item: &T, fill: bool) {
493 crate::prelude::ContainerExtManual::child_set_property(
494 self.as_ref(),
495 &item.clone().upcast(),
496 "fill",
497 &fill,
498 )
499 }
500
501 #[doc(alias = "child.pack-type")]
502 fn child_pack_type<T: IsA<crate::Widget>>(&self, item: &T) -> PackType {
503 crate::prelude::ContainerExtManual::child_property(
504 self.as_ref(),
505 &item.clone().upcast(),
506 "pack-type",
507 )
508 }
509
510 #[doc(alias = "child.pack-type")]
511 fn set_child_pack_type<T: IsA<crate::Widget>>(&self, item: &T, pack_type: PackType) {
512 crate::prelude::ContainerExtManual::child_set_property(
513 self.as_ref(),
514 &item.clone().upcast(),
515 "pack-type",
516 &pack_type,
517 )
518 }
519
520 fn child_padding<T: IsA<crate::Widget>>(&self, item: &T) -> u32 {
521 crate::prelude::ContainerExtManual::child_property(
522 self.as_ref(),
523 &item.clone().upcast(),
524 "padding",
525 )
526 }
527
528 fn set_child_padding<T: IsA<crate::Widget>>(&self, item: &T, padding: u32) {
529 crate::prelude::ContainerExtManual::child_set_property(
530 self.as_ref(),
531 &item.clone().upcast(),
532 "padding",
533 &padding,
534 )
535 }
536
537 fn child_position<T: IsA<crate::Widget>>(&self, item: &T) -> i32 {
538 crate::prelude::ContainerExtManual::child_property(
539 self.as_ref(),
540 &item.clone().upcast(),
541 "position",
542 )
543 }
544
545 fn set_child_position<T: IsA<crate::Widget>>(&self, item: &T, position: i32) {
546 crate::prelude::ContainerExtManual::child_set_property(
547 self.as_ref(),
548 &item.clone().upcast(),
549 "position",
550 &position,
551 )
552 }
553
554 #[doc(alias = "baseline-position")]
555 fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
556 unsafe extern "C" fn notify_baseline_position_trampoline<
557 P: IsA<Box>,
558 F: Fn(&P) + 'static,
559 >(
560 this: *mut ffi::GtkBox,
561 _param_spec: glib::ffi::gpointer,
562 f: glib::ffi::gpointer,
563 ) {
564 let f: &F = &*(f as *const F);
565 f(Box::from_glib_borrow(this).unsafe_cast_ref())
566 }
567 unsafe {
568 let f: Box_<F> = Box_::new(f);
569 connect_raw(
570 self.as_ptr() as *mut _,
571 b"notify::baseline-position\0".as_ptr() as *const _,
572 Some(transmute::<_, unsafe extern "C" fn()>(
573 notify_baseline_position_trampoline::<Self, F> as *const (),
574 )),
575 Box_::into_raw(f),
576 )
577 }
578 }
579
580 #[doc(alias = "homogeneous")]
581 fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
582 unsafe extern "C" fn notify_homogeneous_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
583 this: *mut ffi::GtkBox,
584 _param_spec: glib::ffi::gpointer,
585 f: glib::ffi::gpointer,
586 ) {
587 let f: &F = &*(f as *const F);
588 f(Box::from_glib_borrow(this).unsafe_cast_ref())
589 }
590 unsafe {
591 let f: Box_<F> = Box_::new(f);
592 connect_raw(
593 self.as_ptr() as *mut _,
594 b"notify::homogeneous\0".as_ptr() as *const _,
595 Some(transmute::<_, unsafe extern "C" fn()>(
596 notify_homogeneous_trampoline::<Self, F> as *const (),
597 )),
598 Box_::into_raw(f),
599 )
600 }
601 }
602
603 #[doc(alias = "spacing")]
604 fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
605 unsafe extern "C" fn notify_spacing_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
606 this: *mut ffi::GtkBox,
607 _param_spec: glib::ffi::gpointer,
608 f: glib::ffi::gpointer,
609 ) {
610 let f: &F = &*(f as *const F);
611 f(Box::from_glib_borrow(this).unsafe_cast_ref())
612 }
613 unsafe {
614 let f: Box_<F> = Box_::new(f);
615 connect_raw(
616 self.as_ptr() as *mut _,
617 b"notify::spacing\0".as_ptr() as *const _,
618 Some(transmute::<_, unsafe extern "C" fn()>(
619 notify_spacing_trampoline::<Self, F> as *const (),
620 )),
621 Box_::into_raw(f),
622 )
623 }
624 }
625}
626
627impl<O: IsA<Box>> BoxExt for O {}
628
629impl fmt::Display for Box {
630 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
631 f.write_str("Box")
632 }
633}