Skip to main content

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