gtk4/auto/
box_.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::{
6    ffi, Accessible, AccessibleRole, Align, BaselinePosition, Buildable, ConstraintTarget,
7    LayoutManager, Orientable, Orientation, Overflow, Widget,
8};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    /// Arranges child widgets into a single row or column.
18    ///
19    /// ![An example GtkBox](box.png)
20    ///
21    /// Whether it is a row or column depends on the value of its
22    /// [`orientation`][struct@crate::Orientable#orientation] property. Within the other
23    /// dimension, all children are allocated the same size. The
24    /// [`halign`][struct@crate::Widget#halign] and [`valign`][struct@crate::Widget#valign]
25    /// properties can be used on the children to influence their allocation.
26    ///
27    /// Use repeated calls to [`BoxExt::append()`][crate::prelude::BoxExt::append()] to pack widgets into a
28    /// [`Box`][crate::Box] from start to end. Use [`BoxExt::remove()`][crate::prelude::BoxExt::remove()] to remove widgets
29    /// from the [`Box`][crate::Box]. [`BoxExt::insert_child_after()`][crate::prelude::BoxExt::insert_child_after()] can be used to add
30    /// a child at a particular position.
31    ///
32    /// Use [`BoxExt::set_homogeneous()`][crate::prelude::BoxExt::set_homogeneous()] to specify whether or not all children
33    /// of the [`Box`][crate::Box] are forced to get the same amount of space.
34    ///
35    /// Use [`BoxExt::set_spacing()`][crate::prelude::BoxExt::set_spacing()] to determine how much space will be minimally
36    /// placed between all children in the [`Box`][crate::Box]. Note that spacing is added
37    /// *between* the children.
38    ///
39    /// Use [`BoxExt::reorder_child_after()`][crate::prelude::BoxExt::reorder_child_after()] to move a child to a different
40    /// place in the box.
41    ///
42    /// # CSS nodes
43    ///
44    /// [`Box`][crate::Box] uses a single CSS node with name box.
45    ///
46    /// # Accessibility
47    ///
48    /// Until GTK 4.10, [`Box`][crate::Box] used the [enum@Gtk.AccessibleRole.group] role.
49    ///
50    /// Starting from GTK 4.12, [`Box`][crate::Box] uses the [enum@Gtk.AccessibleRole.generic] role.
51    ///
52    /// ## Properties
53    ///
54    ///
55    /// #### `baseline-child`
56    ///  The position of the child that determines the baseline.
57    ///
58    /// This is only relevant if the box is in vertical orientation.
59    ///
60    /// Readable | Writeable
61    ///
62    ///
63    /// #### `baseline-position`
64    ///  How to position baseline-aligned widgets if extra space is available.
65    ///
66    /// Readable | Writeable
67    ///
68    ///
69    /// #### `homogeneous`
70    ///  Whether the children should all be the same size.
71    ///
72    /// Readable | Writeable
73    ///
74    ///
75    /// #### `spacing`
76    ///  The amount of space between children.
77    ///
78    /// Readable | Writeable
79    /// <details><summary><h4>Widget</h4></summary>
80    ///
81    ///
82    /// #### `can-focus`
83    ///  Whether the widget or any of its descendents can accept
84    /// the input focus.
85    ///
86    /// This property is meant to be set by widget implementations,
87    /// typically in their instance init function.
88    ///
89    /// Readable | Writeable
90    ///
91    ///
92    /// #### `can-target`
93    ///  Whether the widget can receive pointer events.
94    ///
95    /// Readable | Writeable
96    ///
97    ///
98    /// #### `css-classes`
99    ///  A list of css classes applied to this widget.
100    ///
101    /// Readable | Writeable
102    ///
103    ///
104    /// #### `css-name`
105    ///  The name of this widget in the CSS tree.
106    ///
107    /// This property is meant to be set by widget implementations,
108    /// typically in their instance init function.
109    ///
110    /// Readable | Writeable | Construct Only
111    ///
112    ///
113    /// #### `cursor`
114    ///  The cursor used by @widget.
115    ///
116    /// Readable | Writeable
117    ///
118    ///
119    /// #### `focus-on-click`
120    ///  Whether the widget should grab focus when it is clicked with the mouse.
121    ///
122    /// This property is only relevant for widgets that can take focus.
123    ///
124    /// Readable | Writeable
125    ///
126    ///
127    /// #### `focusable`
128    ///  Whether this widget itself will accept the input focus.
129    ///
130    /// Readable | Writeable
131    ///
132    ///
133    /// #### `halign`
134    ///  How to distribute horizontal space if widget gets extra space.
135    ///
136    /// Readable | Writeable
137    ///
138    ///
139    /// #### `has-default`
140    ///  Whether the widget is the default widget.
141    ///
142    /// Readable
143    ///
144    ///
145    /// #### `has-focus`
146    ///  Whether the widget has the input focus.
147    ///
148    /// Readable
149    ///
150    ///
151    /// #### `has-tooltip`
152    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
153    /// signal on @widget.
154    ///
155    /// A true value indicates that @widget can have a tooltip, in this case
156    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
157    /// determine whether it will provide a tooltip or not.
158    ///
159    /// Readable | Writeable
160    ///
161    ///
162    /// #### `height-request`
163    ///  Overrides for height request of the widget.
164    ///
165    /// If this is -1, the natural request will be used.
166    ///
167    /// Readable | Writeable
168    ///
169    ///
170    /// #### `hexpand`
171    ///  Whether to expand horizontally.
172    ///
173    /// Readable | Writeable
174    ///
175    ///
176    /// #### `hexpand-set`
177    ///  Whether to use the `hexpand` property.
178    ///
179    /// Readable | Writeable
180    ///
181    ///
182    /// #### `layout-manager`
183    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
184    /// the preferred size of the widget, and allocate its children.
185    ///
186    /// This property is meant to be set by widget implementations,
187    /// typically in their instance init function.
188    ///
189    /// Readable | Writeable
190    ///
191    ///
192    /// #### `limit-events`
193    ///  Makes this widget act like a modal dialog, with respect to
194    /// event delivery.
195    ///
196    /// Global event controllers will not handle events with targets
197    /// inside the widget, unless they are set up to ignore propagation
198    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
199    ///
200    /// Readable | Writeable
201    ///
202    ///
203    /// #### `margin-bottom`
204    ///  Margin on bottom side of widget.
205    ///
206    /// This property adds margin outside of the widget's normal size
207    /// request, the margin will be added in addition to the size from
208    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
209    ///
210    /// Readable | Writeable
211    ///
212    ///
213    /// #### `margin-end`
214    ///  Margin on end of widget, horizontally.
215    ///
216    /// This property supports left-to-right and right-to-left text
217    /// directions.
218    ///
219    /// This property adds margin outside of the widget's normal size
220    /// request, the margin will be added in addition to the size from
221    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
222    ///
223    /// Readable | Writeable
224    ///
225    ///
226    /// #### `margin-start`
227    ///  Margin on start of widget, horizontally.
228    ///
229    /// This property supports left-to-right and right-to-left text
230    /// directions.
231    ///
232    /// This property adds margin outside of the widget's normal size
233    /// request, the margin will be added in addition to the size from
234    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
235    ///
236    /// Readable | Writeable
237    ///
238    ///
239    /// #### `margin-top`
240    ///  Margin on top side of widget.
241    ///
242    /// This property adds margin outside of the widget's normal size
243    /// request, the margin will be added in addition to the size from
244    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
245    ///
246    /// Readable | Writeable
247    ///
248    ///
249    /// #### `name`
250    ///  The name of the widget.
251    ///
252    /// Readable | Writeable
253    ///
254    ///
255    /// #### `opacity`
256    ///  The requested opacity of the widget.
257    ///
258    /// Readable | Writeable
259    ///
260    ///
261    /// #### `overflow`
262    ///  How content outside the widget's content area is treated.
263    ///
264    /// This property is meant to be set by widget implementations,
265    /// typically in their instance init function.
266    ///
267    /// Readable | Writeable
268    ///
269    ///
270    /// #### `parent`
271    ///  The parent widget of this widget.
272    ///
273    /// Readable
274    ///
275    ///
276    /// #### `receives-default`
277    ///  Whether the widget will receive the default action when it is focused.
278    ///
279    /// Readable | Writeable
280    ///
281    ///
282    /// #### `root`
283    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
284    ///
285    /// This will be `NULL` if the widget is not contained in a root widget.
286    ///
287    /// Readable
288    ///
289    ///
290    /// #### `scale-factor`
291    ///  The scale factor of the widget.
292    ///
293    /// Readable
294    ///
295    ///
296    /// #### `sensitive`
297    ///  Whether the widget responds to input.
298    ///
299    /// Readable | Writeable
300    ///
301    ///
302    /// #### `tooltip-markup`
303    ///  Sets the text of tooltip to be the given string, which is marked up
304    /// with Pango markup.
305    ///
306    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
307    ///
308    /// This is a convenience property which will take care of getting the
309    /// tooltip shown if the given string is not `NULL`:
310    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
311    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
312    /// the default signal handler.
313    ///
314    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
315    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
316    ///
317    /// Readable | Writeable
318    ///
319    ///
320    /// #### `tooltip-text`
321    ///  Sets the text of tooltip to be the given string.
322    ///
323    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
324    ///
325    /// This is a convenience property which will take care of getting the
326    /// tooltip shown if the given string is not `NULL`:
327    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
328    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
329    /// the default signal handler.
330    ///
331    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
332    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
333    ///
334    /// Readable | Writeable
335    ///
336    ///
337    /// #### `valign`
338    ///  How to distribute vertical space if widget gets extra space.
339    ///
340    /// Readable | Writeable
341    ///
342    ///
343    /// #### `vexpand`
344    ///  Whether to expand vertically.
345    ///
346    /// Readable | Writeable
347    ///
348    ///
349    /// #### `vexpand-set`
350    ///  Whether to use the `vexpand` property.
351    ///
352    /// Readable | Writeable
353    ///
354    ///
355    /// #### `visible`
356    ///  Whether the widget is visible.
357    ///
358    /// Readable | Writeable
359    ///
360    ///
361    /// #### `width-request`
362    ///  Overrides for width request of the widget.
363    ///
364    /// If this is -1, the natural request will be used.
365    ///
366    /// Readable | Writeable
367    /// </details>
368    /// <details><summary><h4>Accessible</h4></summary>
369    ///
370    ///
371    /// #### `accessible-role`
372    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
373    ///
374    /// The accessible role cannot be changed once set.
375    ///
376    /// Readable | Writeable
377    /// </details>
378    /// <details><summary><h4>Orientable</h4></summary>
379    ///
380    ///
381    /// #### `orientation`
382    ///  The orientation of the orientable.
383    ///
384    /// Readable | Writeable
385    /// </details>
386    ///
387    /// # Implements
388    ///
389    /// [`BoxExt`][trait@crate::prelude::BoxExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
390    #[doc(alias = "GtkBox")]
391    pub struct Box(Object<ffi::GtkBox, ffi::GtkBoxClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
392
393    match fn {
394        type_ => || ffi::gtk_box_get_type(),
395    }
396}
397
398impl Box {
399    pub const NONE: Option<&'static Box> = None;
400
401    /// Creates a new box.
402    /// ## `orientation`
403    /// the box’s orientation
404    /// ## `spacing`
405    /// the number of pixels to place between children
406    ///
407    /// # Returns
408    ///
409    /// a new [`Box`][crate::Box].
410    #[doc(alias = "gtk_box_new")]
411    pub fn new(orientation: Orientation, spacing: i32) -> Box {
412        assert_initialized_main_thread!();
413        unsafe {
414            Widget::from_glib_none(ffi::gtk_box_new(orientation.into_glib(), spacing)).unsafe_cast()
415        }
416    }
417
418    // rustdoc-stripper-ignore-next
419    /// Creates a new builder-pattern struct instance to construct [`Box`] objects.
420    ///
421    /// This method returns an instance of [`BoxBuilder`](crate::builders::BoxBuilder) which can be used to create [`Box`] objects.
422    pub fn builder() -> BoxBuilder {
423        BoxBuilder::new()
424    }
425}
426
427impl Default for Box {
428    fn default() -> Self {
429        glib::object::Object::new::<Self>()
430    }
431}
432
433// rustdoc-stripper-ignore-next
434/// A [builder-pattern] type to construct [`Box`] objects.
435///
436/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
437#[must_use = "The builder must be built to be used"]
438pub struct BoxBuilder {
439    builder: glib::object::ObjectBuilder<'static, Box>,
440}
441
442impl BoxBuilder {
443    fn new() -> Self {
444        Self {
445            builder: glib::object::Object::builder(),
446        }
447    }
448
449    /// The position of the child that determines the baseline.
450    ///
451    /// This is only relevant if the box is in vertical orientation.
452    #[cfg(feature = "v4_12")]
453    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
454    pub fn baseline_child(self, baseline_child: i32) -> Self {
455        Self {
456            builder: self.builder.property("baseline-child", baseline_child),
457        }
458    }
459
460    /// How to position baseline-aligned widgets if extra space is available.
461    pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
462        Self {
463            builder: self
464                .builder
465                .property("baseline-position", baseline_position),
466        }
467    }
468
469    /// Whether the children should all be the same size.
470    pub fn homogeneous(self, homogeneous: bool) -> Self {
471        Self {
472            builder: self.builder.property("homogeneous", homogeneous),
473        }
474    }
475
476    /// The amount of space between children.
477    pub fn spacing(self, spacing: i32) -> Self {
478        Self {
479            builder: self.builder.property("spacing", spacing),
480        }
481    }
482
483    /// Whether the widget or any of its descendents can accept
484    /// the input focus.
485    ///
486    /// This property is meant to be set by widget implementations,
487    /// typically in their instance init function.
488    pub fn can_focus(self, can_focus: bool) -> Self {
489        Self {
490            builder: self.builder.property("can-focus", can_focus),
491        }
492    }
493
494    /// Whether the widget can receive pointer events.
495    pub fn can_target(self, can_target: bool) -> Self {
496        Self {
497            builder: self.builder.property("can-target", can_target),
498        }
499    }
500
501    /// A list of css classes applied to this widget.
502    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
503        Self {
504            builder: self.builder.property("css-classes", css_classes.into()),
505        }
506    }
507
508    /// The name of this widget in the CSS tree.
509    ///
510    /// This property is meant to be set by widget implementations,
511    /// typically in their instance init function.
512    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
513        Self {
514            builder: self.builder.property("css-name", css_name.into()),
515        }
516    }
517
518    /// The cursor used by @widget.
519    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
520        Self {
521            builder: self.builder.property("cursor", cursor.clone()),
522        }
523    }
524
525    /// Whether the widget should grab focus when it is clicked with the mouse.
526    ///
527    /// This property is only relevant for widgets that can take focus.
528    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
529        Self {
530            builder: self.builder.property("focus-on-click", focus_on_click),
531        }
532    }
533
534    /// Whether this widget itself will accept the input focus.
535    pub fn focusable(self, focusable: bool) -> Self {
536        Self {
537            builder: self.builder.property("focusable", focusable),
538        }
539    }
540
541    /// How to distribute horizontal space if widget gets extra space.
542    pub fn halign(self, halign: Align) -> Self {
543        Self {
544            builder: self.builder.property("halign", halign),
545        }
546    }
547
548    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
549    /// signal on @widget.
550    ///
551    /// A true value indicates that @widget can have a tooltip, in this case
552    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
553    /// determine whether it will provide a tooltip or not.
554    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
555        Self {
556            builder: self.builder.property("has-tooltip", has_tooltip),
557        }
558    }
559
560    /// Overrides for height request of the widget.
561    ///
562    /// If this is -1, the natural request will be used.
563    pub fn height_request(self, height_request: i32) -> Self {
564        Self {
565            builder: self.builder.property("height-request", height_request),
566        }
567    }
568
569    /// Whether to expand horizontally.
570    pub fn hexpand(self, hexpand: bool) -> Self {
571        Self {
572            builder: self.builder.property("hexpand", hexpand),
573        }
574    }
575
576    /// Whether to use the `hexpand` property.
577    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
578        Self {
579            builder: self.builder.property("hexpand-set", hexpand_set),
580        }
581    }
582
583    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
584    /// the preferred size of the widget, and allocate its children.
585    ///
586    /// This property is meant to be set by widget implementations,
587    /// typically in their instance init function.
588    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
589        Self {
590            builder: self
591                .builder
592                .property("layout-manager", layout_manager.clone().upcast()),
593        }
594    }
595
596    /// Makes this widget act like a modal dialog, with respect to
597    /// event delivery.
598    ///
599    /// Global event controllers will not handle events with targets
600    /// inside the widget, unless they are set up to ignore propagation
601    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
602    #[cfg(feature = "v4_18")]
603    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
604    pub fn limit_events(self, limit_events: bool) -> Self {
605        Self {
606            builder: self.builder.property("limit-events", limit_events),
607        }
608    }
609
610    /// Margin on bottom side of widget.
611    ///
612    /// This property adds margin outside of the widget's normal size
613    /// request, the margin will be added in addition to the size from
614    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
615    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
616        Self {
617            builder: self.builder.property("margin-bottom", margin_bottom),
618        }
619    }
620
621    /// Margin on end of widget, horizontally.
622    ///
623    /// This property supports left-to-right and right-to-left text
624    /// directions.
625    ///
626    /// This property adds margin outside of the widget's normal size
627    /// request, the margin will be added in addition to the size from
628    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
629    pub fn margin_end(self, margin_end: i32) -> Self {
630        Self {
631            builder: self.builder.property("margin-end", margin_end),
632        }
633    }
634
635    /// Margin on start of widget, horizontally.
636    ///
637    /// This property supports left-to-right and right-to-left text
638    /// directions.
639    ///
640    /// This property adds margin outside of the widget's normal size
641    /// request, the margin will be added in addition to the size from
642    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
643    pub fn margin_start(self, margin_start: i32) -> Self {
644        Self {
645            builder: self.builder.property("margin-start", margin_start),
646        }
647    }
648
649    /// Margin on top side of widget.
650    ///
651    /// This property adds margin outside of the widget's normal size
652    /// request, the margin will be added in addition to the size from
653    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
654    pub fn margin_top(self, margin_top: i32) -> Self {
655        Self {
656            builder: self.builder.property("margin-top", margin_top),
657        }
658    }
659
660    /// The name of the widget.
661    pub fn name(self, name: impl Into<glib::GString>) -> Self {
662        Self {
663            builder: self.builder.property("name", name.into()),
664        }
665    }
666
667    /// The requested opacity of the widget.
668    pub fn opacity(self, opacity: f64) -> Self {
669        Self {
670            builder: self.builder.property("opacity", opacity),
671        }
672    }
673
674    /// How content outside the widget's content area is treated.
675    ///
676    /// This property is meant to be set by widget implementations,
677    /// typically in their instance init function.
678    pub fn overflow(self, overflow: Overflow) -> Self {
679        Self {
680            builder: self.builder.property("overflow", overflow),
681        }
682    }
683
684    /// Whether the widget will receive the default action when it is focused.
685    pub fn receives_default(self, receives_default: bool) -> Self {
686        Self {
687            builder: self.builder.property("receives-default", receives_default),
688        }
689    }
690
691    /// Whether the widget responds to input.
692    pub fn sensitive(self, sensitive: bool) -> Self {
693        Self {
694            builder: self.builder.property("sensitive", sensitive),
695        }
696    }
697
698    /// Sets the text of tooltip to be the given string, which is marked up
699    /// with Pango markup.
700    ///
701    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
702    ///
703    /// This is a convenience property which will take care of getting the
704    /// tooltip shown if the given string is not `NULL`:
705    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
706    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
707    /// the default signal handler.
708    ///
709    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
710    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
711    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
712        Self {
713            builder: self
714                .builder
715                .property("tooltip-markup", tooltip_markup.into()),
716        }
717    }
718
719    /// Sets the text of tooltip to be the given string.
720    ///
721    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
722    ///
723    /// This is a convenience property which will take care of getting the
724    /// tooltip shown if the given string is not `NULL`:
725    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
726    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
727    /// the default signal handler.
728    ///
729    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
730    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
731    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
732        Self {
733            builder: self.builder.property("tooltip-text", tooltip_text.into()),
734        }
735    }
736
737    /// How to distribute vertical space if widget gets extra space.
738    pub fn valign(self, valign: Align) -> Self {
739        Self {
740            builder: self.builder.property("valign", valign),
741        }
742    }
743
744    /// Whether to expand vertically.
745    pub fn vexpand(self, vexpand: bool) -> Self {
746        Self {
747            builder: self.builder.property("vexpand", vexpand),
748        }
749    }
750
751    /// Whether to use the `vexpand` property.
752    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
753        Self {
754            builder: self.builder.property("vexpand-set", vexpand_set),
755        }
756    }
757
758    /// Whether the widget is visible.
759    pub fn visible(self, visible: bool) -> Self {
760        Self {
761            builder: self.builder.property("visible", visible),
762        }
763    }
764
765    /// Overrides for width request of the widget.
766    ///
767    /// If this is -1, the natural request will be used.
768    pub fn width_request(self, width_request: i32) -> Self {
769        Self {
770            builder: self.builder.property("width-request", width_request),
771        }
772    }
773
774    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
775    ///
776    /// The accessible role cannot be changed once set.
777    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
778        Self {
779            builder: self.builder.property("accessible-role", accessible_role),
780        }
781    }
782
783    /// The orientation of the orientable.
784    pub fn orientation(self, orientation: Orientation) -> Self {
785        Self {
786            builder: self.builder.property("orientation", orientation),
787        }
788    }
789
790    // rustdoc-stripper-ignore-next
791    /// Build the [`Box`].
792    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
793    pub fn build(self) -> Box {
794        assert_initialized_main_thread!();
795        self.builder.build()
796    }
797}
798
799mod sealed {
800    pub trait Sealed {}
801    impl<T: super::IsA<super::Box>> Sealed for T {}
802}
803
804/// Trait containing all [`struct@Box`] methods.
805///
806/// # Implementors
807///
808/// [`Box`][struct@crate::Box], [`ShortcutsGroup`][struct@crate::ShortcutsGroup], [`ShortcutsSection`][struct@crate::ShortcutsSection]
809pub trait BoxExt: IsA<Box> + sealed::Sealed + 'static {
810    /// Adds a child at the end.
811    /// ## `child`
812    /// the widget to append
813    #[doc(alias = "gtk_box_append")]
814    fn append(&self, child: &impl IsA<Widget>) {
815        unsafe {
816            ffi::gtk_box_append(
817                self.as_ref().to_glib_none().0,
818                child.as_ref().to_glib_none().0,
819            );
820        }
821    }
822
823    /// Gets the value set by [`set_baseline_child()`][Self::set_baseline_child()].
824    ///
825    /// # Returns
826    ///
827    /// the baseline child
828    #[cfg(feature = "v4_12")]
829    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
830    #[doc(alias = "gtk_box_get_baseline_child")]
831    #[doc(alias = "get_baseline_child")]
832    #[doc(alias = "baseline-child")]
833    fn baseline_child(&self) -> i32 {
834        unsafe { ffi::gtk_box_get_baseline_child(self.as_ref().to_glib_none().0) }
835    }
836
837    /// Gets the value set by [`set_baseline_position()`][Self::set_baseline_position()].
838    ///
839    /// # Returns
840    ///
841    /// the baseline position
842    #[doc(alias = "gtk_box_get_baseline_position")]
843    #[doc(alias = "get_baseline_position")]
844    #[doc(alias = "baseline-position")]
845    fn baseline_position(&self) -> BaselinePosition {
846        unsafe {
847            from_glib(ffi::gtk_box_get_baseline_position(
848                self.as_ref().to_glib_none().0,
849            ))
850        }
851    }
852
853    /// Returns whether the box is homogeneous.
854    ///
855    /// In a homogeneous box all children are the same size.
856    ///
857    /// # Returns
858    ///
859    /// true if the box is homogeneous
860    #[doc(alias = "gtk_box_get_homogeneous")]
861    #[doc(alias = "get_homogeneous")]
862    #[doc(alias = "homogeneous")]
863    fn is_homogeneous(&self) -> bool {
864        unsafe { from_glib(ffi::gtk_box_get_homogeneous(self.as_ref().to_glib_none().0)) }
865    }
866
867    /// Gets the value set by [`set_spacing()`][Self::set_spacing()].
868    ///
869    /// # Returns
870    ///
871    /// spacing between children
872    #[doc(alias = "gtk_box_get_spacing")]
873    #[doc(alias = "get_spacing")]
874    fn spacing(&self) -> i32 {
875        unsafe { ffi::gtk_box_get_spacing(self.as_ref().to_glib_none().0) }
876    }
877
878    /// Inserts a child at a specific position.
879    ///
880    /// The child is added after @sibling in the list of @self children.
881    ///
882    /// If @sibling is `NULL`, the @child is placed at the beginning.
883    /// ## `child`
884    /// the widget to insert
885    /// ## `sibling`
886    /// the sibling after which to insert @child
887    #[doc(alias = "gtk_box_insert_child_after")]
888    fn insert_child_after(&self, child: &impl IsA<Widget>, sibling: Option<&impl IsA<Widget>>) {
889        unsafe {
890            ffi::gtk_box_insert_child_after(
891                self.as_ref().to_glib_none().0,
892                child.as_ref().to_glib_none().0,
893                sibling.map(|p| p.as_ref()).to_glib_none().0,
894            );
895        }
896    }
897
898    /// Adds a child at the beginning.
899    /// ## `child`
900    /// the widget to prepend
901    #[doc(alias = "gtk_box_prepend")]
902    fn prepend(&self, child: &impl IsA<Widget>) {
903        unsafe {
904            ffi::gtk_box_prepend(
905                self.as_ref().to_glib_none().0,
906                child.as_ref().to_glib_none().0,
907            );
908        }
909    }
910
911    /// Removes a child widget from the box.
912    ///
913    /// The child must have been added before with
914    /// [`append()`][Self::append()], [`prepend()`][Self::prepend()], or
915    /// [`insert_child_after()`][Self::insert_child_after()].
916    /// ## `child`
917    /// the child to remove
918    #[doc(alias = "gtk_box_remove")]
919    fn remove(&self, child: &impl IsA<Widget>) {
920        unsafe {
921            ffi::gtk_box_remove(
922                self.as_ref().to_glib_none().0,
923                child.as_ref().to_glib_none().0,
924            );
925        }
926    }
927
928    /// Moves a child to a different position.
929    ///
930    /// The child is moved to the position after @sibling in the list
931    /// of @self children.
932    ///
933    /// If @sibling is `NULL`, the child is placed at the beginning.
934    /// ## `child`
935    /// the widget to move, must be a child of @self
936    /// ## `sibling`
937    /// the sibling to move @child after
938    #[doc(alias = "gtk_box_reorder_child_after")]
939    fn reorder_child_after(&self, child: &impl IsA<Widget>, sibling: Option<&impl IsA<Widget>>) {
940        unsafe {
941            ffi::gtk_box_reorder_child_after(
942                self.as_ref().to_glib_none().0,
943                child.as_ref().to_glib_none().0,
944                sibling.map(|p| p.as_ref()).to_glib_none().0,
945            );
946        }
947    }
948
949    /// Sets the baseline child of a box.
950    ///
951    /// This affects only vertical boxes.
952    /// ## `child`
953    /// a child position, or -1
954    #[cfg(feature = "v4_12")]
955    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
956    #[doc(alias = "gtk_box_set_baseline_child")]
957    #[doc(alias = "baseline-child")]
958    fn set_baseline_child(&self, child: i32) {
959        unsafe {
960            ffi::gtk_box_set_baseline_child(self.as_ref().to_glib_none().0, child);
961        }
962    }
963
964    /// Sets the baseline position of a box.
965    ///
966    /// This affects only horizontal boxes with at least one baseline
967    /// aligned child. If there is more vertical space available than
968    /// requested, and the baseline is not allocated by the parent then
969    /// @position is used to allocate the baseline with respect to the
970    /// extra space available.
971    /// ## `position`
972    /// the baseline position
973    #[doc(alias = "gtk_box_set_baseline_position")]
974    #[doc(alias = "baseline-position")]
975    fn set_baseline_position(&self, position: BaselinePosition) {
976        unsafe {
977            ffi::gtk_box_set_baseline_position(
978                self.as_ref().to_glib_none().0,
979                position.into_glib(),
980            );
981        }
982    }
983
984    /// Sets whether or not all children are given equal space
985    /// in the box.
986    /// ## `homogeneous`
987    /// true to create equal allotments,
988    ///   false for variable allotments
989    #[doc(alias = "gtk_box_set_homogeneous")]
990    #[doc(alias = "homogeneous")]
991    fn set_homogeneous(&self, homogeneous: bool) {
992        unsafe {
993            ffi::gtk_box_set_homogeneous(self.as_ref().to_glib_none().0, homogeneous.into_glib());
994        }
995    }
996
997    /// Sets the number of pixels to place between children.
998    /// ## `spacing`
999    /// the number of pixels to put between children
1000    #[doc(alias = "gtk_box_set_spacing")]
1001    #[doc(alias = "spacing")]
1002    fn set_spacing(&self, spacing: i32) {
1003        unsafe {
1004            ffi::gtk_box_set_spacing(self.as_ref().to_glib_none().0, spacing);
1005        }
1006    }
1007
1008    #[cfg(feature = "v4_12")]
1009    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1010    #[doc(alias = "baseline-child")]
1011    fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1012        unsafe extern "C" fn notify_baseline_child_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1013            this: *mut ffi::GtkBox,
1014            _param_spec: glib::ffi::gpointer,
1015            f: glib::ffi::gpointer,
1016        ) {
1017            let f: &F = &*(f as *const F);
1018            f(Box::from_glib_borrow(this).unsafe_cast_ref())
1019        }
1020        unsafe {
1021            let f: Box_<F> = Box_::new(f);
1022            connect_raw(
1023                self.as_ptr() as *mut _,
1024                b"notify::baseline-child\0".as_ptr() as *const _,
1025                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1026                    notify_baseline_child_trampoline::<Self, F> as *const (),
1027                )),
1028                Box_::into_raw(f),
1029            )
1030        }
1031    }
1032
1033    #[doc(alias = "baseline-position")]
1034    fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1035        unsafe extern "C" fn notify_baseline_position_trampoline<
1036            P: IsA<Box>,
1037            F: Fn(&P) + 'static,
1038        >(
1039            this: *mut ffi::GtkBox,
1040            _param_spec: glib::ffi::gpointer,
1041            f: glib::ffi::gpointer,
1042        ) {
1043            let f: &F = &*(f as *const F);
1044            f(Box::from_glib_borrow(this).unsafe_cast_ref())
1045        }
1046        unsafe {
1047            let f: Box_<F> = Box_::new(f);
1048            connect_raw(
1049                self.as_ptr() as *mut _,
1050                b"notify::baseline-position\0".as_ptr() as *const _,
1051                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1052                    notify_baseline_position_trampoline::<Self, F> as *const (),
1053                )),
1054                Box_::into_raw(f),
1055            )
1056        }
1057    }
1058
1059    #[doc(alias = "homogeneous")]
1060    fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1061        unsafe extern "C" fn notify_homogeneous_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1062            this: *mut ffi::GtkBox,
1063            _param_spec: glib::ffi::gpointer,
1064            f: glib::ffi::gpointer,
1065        ) {
1066            let f: &F = &*(f as *const F);
1067            f(Box::from_glib_borrow(this).unsafe_cast_ref())
1068        }
1069        unsafe {
1070            let f: Box_<F> = Box_::new(f);
1071            connect_raw(
1072                self.as_ptr() as *mut _,
1073                b"notify::homogeneous\0".as_ptr() as *const _,
1074                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1075                    notify_homogeneous_trampoline::<Self, F> as *const (),
1076                )),
1077                Box_::into_raw(f),
1078            )
1079        }
1080    }
1081
1082    #[doc(alias = "spacing")]
1083    fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1084        unsafe extern "C" fn notify_spacing_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1085            this: *mut ffi::GtkBox,
1086            _param_spec: glib::ffi::gpointer,
1087            f: glib::ffi::gpointer,
1088        ) {
1089            let f: &F = &*(f as *const F);
1090            f(Box::from_glib_borrow(this).unsafe_cast_ref())
1091        }
1092        unsafe {
1093            let f: Box_<F> = Box_::new(f);
1094            connect_raw(
1095                self.as_ptr() as *mut _,
1096                b"notify::spacing\0".as_ptr() as *const _,
1097                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1098                    notify_spacing_trampoline::<Self, F> as *const (),
1099                )),
1100                Box_::into_raw(f),
1101            )
1102        }
1103    }
1104}
1105
1106impl<O: IsA<Box>> BoxExt for O {}