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    /// <picture>
20    ///   <source srcset="box-dark.png" media="(prefers-color-scheme: dark)">
21    ///   <img alt="An example GtkBox" src="box.png">
22    /// </picture>
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 | Writeable
64    ///
65    ///
66    /// #### `baseline-position`
67    ///  How to position baseline-aligned widgets if extra space is available.
68    ///
69    /// Readable | Writeable
70    ///
71    ///
72    /// #### `homogeneous`
73    ///  Whether the children should all be the same size.
74    ///
75    /// Readable | Writeable
76    ///
77    ///
78    /// #### `spacing`
79    ///  The amount of space between children.
80    ///
81    /// Readable | Writeable
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 | Writeable
93    ///
94    ///
95    /// #### `can-target`
96    ///  Whether the widget can receive pointer events.
97    ///
98    /// Readable | Writeable
99    ///
100    ///
101    /// #### `css-classes`
102    ///  A list of css classes applied to this widget.
103    ///
104    /// Readable | Writeable
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 | Writeable | Construct Only
114    ///
115    ///
116    /// #### `cursor`
117    ///  The cursor used by @widget.
118    ///
119    /// Readable | Writeable
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 | Writeable
128    ///
129    ///
130    /// #### `focusable`
131    ///  Whether this widget itself will accept the input focus.
132    ///
133    /// Readable | Writeable
134    ///
135    ///
136    /// #### `halign`
137    ///  How to distribute horizontal space if widget gets extra space.
138    ///
139    /// Readable | Writeable
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 | Writeable
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 | Writeable
171    ///
172    ///
173    /// #### `hexpand`
174    ///  Whether to expand horizontally.
175    ///
176    /// Readable | Writeable
177    ///
178    ///
179    /// #### `hexpand-set`
180    ///  Whether to use the `hexpand` property.
181    ///
182    /// Readable | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
250    ///
251    ///
252    /// #### `name`
253    ///  The name of the widget.
254    ///
255    /// Readable | Writeable
256    ///
257    ///
258    /// #### `opacity`
259    ///  The requested opacity of the widget.
260    ///
261    /// Readable | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
338    ///
339    ///
340    /// #### `valign`
341    ///  How to distribute vertical space if widget gets extra space.
342    ///
343    /// Readable | Writeable
344    ///
345    ///
346    /// #### `vexpand`
347    ///  Whether to expand vertically.
348    ///
349    /// Readable | Writeable
350    ///
351    ///
352    /// #### `vexpand-set`
353    ///  Whether to use the `vexpand` property.
354    ///
355    /// Readable | Writeable
356    ///
357    ///
358    /// #### `visible`
359    ///  Whether the widget is visible.
360    ///
361    /// Readable | Writeable
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 | Writeable
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 | Writeable
380    /// </details>
381    /// <details><summary><h4>Orientable</h4></summary>
382    ///
383    ///
384    /// #### `orientation`
385    ///  The orientation of the orientable.
386    ///
387    /// Readable | Writeable
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
401impl Box {
402    pub const NONE: Option<&'static Box> = None;
403
404    /// Creates a new box.
405    /// ## `orientation`
406    /// the box’s orientation
407    /// ## `spacing`
408    /// the number of pixels to place between children
409    ///
410    /// # Returns
411    ///
412    /// a new [`Box`][crate::Box].
413    #[doc(alias = "gtk_box_new")]
414    pub fn new(orientation: Orientation, spacing: i32) -> Box {
415        assert_initialized_main_thread!();
416        unsafe {
417            Widget::from_glib_none(ffi::gtk_box_new(orientation.into_glib(), spacing)).unsafe_cast()
418        }
419    }
420
421    // rustdoc-stripper-ignore-next
422    /// Creates a new builder-pattern struct instance to construct [`Box`] objects.
423    ///
424    /// This method returns an instance of [`BoxBuilder`](crate::builders::BoxBuilder) which can be used to create [`Box`] objects.
425    pub fn builder() -> BoxBuilder {
426        BoxBuilder::new()
427    }
428}
429
430impl Default for Box {
431    fn default() -> Self {
432        glib::object::Object::new::<Self>()
433    }
434}
435
436// rustdoc-stripper-ignore-next
437/// A [builder-pattern] type to construct [`Box`] objects.
438///
439/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
440#[must_use = "The builder must be built to be used"]
441pub struct BoxBuilder {
442    builder: glib::object::ObjectBuilder<'static, Box>,
443}
444
445impl BoxBuilder {
446    fn new() -> Self {
447        Self {
448            builder: glib::object::Object::builder(),
449        }
450    }
451
452    /// The position of the child that determines the baseline.
453    ///
454    /// This is only relevant if the box is in vertical orientation.
455    #[cfg(feature = "v4_12")]
456    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
457    pub fn baseline_child(self, baseline_child: i32) -> Self {
458        Self {
459            builder: self.builder.property("baseline-child", baseline_child),
460        }
461    }
462
463    /// How to position baseline-aligned widgets if extra space is available.
464    pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
465        Self {
466            builder: self
467                .builder
468                .property("baseline-position", baseline_position),
469        }
470    }
471
472    /// Whether the children should all be the same size.
473    pub fn homogeneous(self, homogeneous: bool) -> Self {
474        Self {
475            builder: self.builder.property("homogeneous", homogeneous),
476        }
477    }
478
479    /// The amount of space between children.
480    pub fn spacing(self, spacing: i32) -> Self {
481        Self {
482            builder: self.builder.property("spacing", spacing),
483        }
484    }
485
486    /// Whether the widget or any of its descendents can accept
487    /// the input focus.
488    ///
489    /// This property is meant to be set by widget implementations,
490    /// typically in their instance init function.
491    pub fn can_focus(self, can_focus: bool) -> Self {
492        Self {
493            builder: self.builder.property("can-focus", can_focus),
494        }
495    }
496
497    /// Whether the widget can receive pointer events.
498    pub fn can_target(self, can_target: bool) -> Self {
499        Self {
500            builder: self.builder.property("can-target", can_target),
501        }
502    }
503
504    /// A list of css classes applied to this widget.
505    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
506        Self {
507            builder: self.builder.property("css-classes", css_classes.into()),
508        }
509    }
510
511    /// The name of this widget in the CSS tree.
512    ///
513    /// This property is meant to be set by widget implementations,
514    /// typically in their instance init function.
515    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
516        Self {
517            builder: self.builder.property("css-name", css_name.into()),
518        }
519    }
520
521    /// The cursor used by @widget.
522    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
523        Self {
524            builder: self.builder.property("cursor", cursor.clone()),
525        }
526    }
527
528    /// Whether the widget should grab focus when it is clicked with the mouse.
529    ///
530    /// This property is only relevant for widgets that can take focus.
531    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
532        Self {
533            builder: self.builder.property("focus-on-click", focus_on_click),
534        }
535    }
536
537    /// Whether this widget itself will accept the input focus.
538    pub fn focusable(self, focusable: bool) -> Self {
539        Self {
540            builder: self.builder.property("focusable", focusable),
541        }
542    }
543
544    /// How to distribute horizontal space if widget gets extra space.
545    pub fn halign(self, halign: Align) -> Self {
546        Self {
547            builder: self.builder.property("halign", halign),
548        }
549    }
550
551    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
552    /// signal on @widget.
553    ///
554    /// A true value indicates that @widget can have a tooltip, in this case
555    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
556    /// determine whether it will provide a tooltip or not.
557    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
558        Self {
559            builder: self.builder.property("has-tooltip", has_tooltip),
560        }
561    }
562
563    /// Overrides for height request of the widget.
564    ///
565    /// If this is -1, the natural request will be used.
566    pub fn height_request(self, height_request: i32) -> Self {
567        Self {
568            builder: self.builder.property("height-request", height_request),
569        }
570    }
571
572    /// Whether to expand horizontally.
573    pub fn hexpand(self, hexpand: bool) -> Self {
574        Self {
575            builder: self.builder.property("hexpand", hexpand),
576        }
577    }
578
579    /// Whether to use the `hexpand` property.
580    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
581        Self {
582            builder: self.builder.property("hexpand-set", hexpand_set),
583        }
584    }
585
586    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
587    /// the preferred size of the widget, and allocate its children.
588    ///
589    /// This property is meant to be set by widget implementations,
590    /// typically in their instance init function.
591    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
592        Self {
593            builder: self
594                .builder
595                .property("layout-manager", layout_manager.clone().upcast()),
596        }
597    }
598
599    /// Makes this widget act like a modal dialog, with respect to
600    /// event delivery.
601    ///
602    /// Global event controllers will not handle events with targets
603    /// inside the widget, unless they are set up to ignore propagation
604    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
605    #[cfg(feature = "v4_18")]
606    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
607    pub fn limit_events(self, limit_events: bool) -> Self {
608        Self {
609            builder: self.builder.property("limit-events", limit_events),
610        }
611    }
612
613    /// Margin on bottom side of widget.
614    ///
615    /// This property adds margin outside of the widget's normal size
616    /// request, the margin will be added in addition to the size from
617    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
618    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
619        Self {
620            builder: self.builder.property("margin-bottom", margin_bottom),
621        }
622    }
623
624    /// Margin on end of widget, horizontally.
625    ///
626    /// This property supports left-to-right and right-to-left text
627    /// directions.
628    ///
629    /// This property adds margin outside of the widget's normal size
630    /// request, the margin will be added in addition to the size from
631    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
632    pub fn margin_end(self, margin_end: i32) -> Self {
633        Self {
634            builder: self.builder.property("margin-end", margin_end),
635        }
636    }
637
638    /// Margin on start of widget, horizontally.
639    ///
640    /// This property supports left-to-right and right-to-left text
641    /// directions.
642    ///
643    /// This property adds margin outside of the widget's normal size
644    /// request, the margin will be added in addition to the size from
645    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
646    pub fn margin_start(self, margin_start: i32) -> Self {
647        Self {
648            builder: self.builder.property("margin-start", margin_start),
649        }
650    }
651
652    /// Margin on top side of widget.
653    ///
654    /// This property adds margin outside of the widget's normal size
655    /// request, the margin will be added in addition to the size from
656    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
657    pub fn margin_top(self, margin_top: i32) -> Self {
658        Self {
659            builder: self.builder.property("margin-top", margin_top),
660        }
661    }
662
663    /// The name of the widget.
664    pub fn name(self, name: impl Into<glib::GString>) -> Self {
665        Self {
666            builder: self.builder.property("name", name.into()),
667        }
668    }
669
670    /// The requested opacity of the widget.
671    pub fn opacity(self, opacity: f64) -> Self {
672        Self {
673            builder: self.builder.property("opacity", opacity),
674        }
675    }
676
677    /// How content outside the widget's content area is treated.
678    ///
679    /// This property is meant to be set by widget implementations,
680    /// typically in their instance init function.
681    pub fn overflow(self, overflow: Overflow) -> Self {
682        Self {
683            builder: self.builder.property("overflow", overflow),
684        }
685    }
686
687    /// Whether the widget will receive the default action when it is focused.
688    pub fn receives_default(self, receives_default: bool) -> Self {
689        Self {
690            builder: self.builder.property("receives-default", receives_default),
691        }
692    }
693
694    /// Whether the widget responds to input.
695    pub fn sensitive(self, sensitive: bool) -> Self {
696        Self {
697            builder: self.builder.property("sensitive", sensitive),
698        }
699    }
700
701    /// Sets the text of tooltip to be the given string, which is marked up
702    /// with Pango markup.
703    ///
704    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
705    ///
706    /// This is a convenience property which will take care of getting the
707    /// tooltip shown if the given string is not `NULL`:
708    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
709    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
710    /// the default signal handler.
711    ///
712    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
713    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
714    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
715        Self {
716            builder: self
717                .builder
718                .property("tooltip-markup", tooltip_markup.into()),
719        }
720    }
721
722    /// Sets the text of tooltip to be the given string.
723    ///
724    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
725    ///
726    /// This is a convenience property which will take care of getting the
727    /// tooltip shown if the given string is not `NULL`:
728    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
729    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
730    /// the default signal handler.
731    ///
732    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
733    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
734    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
735        Self {
736            builder: self.builder.property("tooltip-text", tooltip_text.into()),
737        }
738    }
739
740    /// How to distribute vertical space if widget gets extra space.
741    pub fn valign(self, valign: Align) -> Self {
742        Self {
743            builder: self.builder.property("valign", valign),
744        }
745    }
746
747    /// Whether to expand vertically.
748    pub fn vexpand(self, vexpand: bool) -> Self {
749        Self {
750            builder: self.builder.property("vexpand", vexpand),
751        }
752    }
753
754    /// Whether to use the `vexpand` property.
755    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
756        Self {
757            builder: self.builder.property("vexpand-set", vexpand_set),
758        }
759    }
760
761    /// Whether the widget is visible.
762    pub fn visible(self, visible: bool) -> Self {
763        Self {
764            builder: self.builder.property("visible", visible),
765        }
766    }
767
768    /// Overrides for width request of the widget.
769    ///
770    /// If this is -1, the natural request will be used.
771    pub fn width_request(self, width_request: i32) -> Self {
772        Self {
773            builder: self.builder.property("width-request", width_request),
774        }
775    }
776
777    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
778    ///
779    /// The accessible role cannot be changed once set.
780    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
781        Self {
782            builder: self.builder.property("accessible-role", accessible_role),
783        }
784    }
785
786    /// The orientation of the orientable.
787    pub fn orientation(self, orientation: Orientation) -> Self {
788        Self {
789            builder: self.builder.property("orientation", orientation),
790        }
791    }
792
793    // rustdoc-stripper-ignore-next
794    /// Build the [`Box`].
795    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
796    pub fn build(self) -> Box {
797        assert_initialized_main_thread!();
798        self.builder.build()
799    }
800}
801
802/// Trait containing all [`struct@Box`] methods.
803///
804/// # Implementors
805///
806/// [`Box`][struct@crate::Box], [`ShortcutsGroup`][struct@crate::ShortcutsGroup], [`ShortcutsSection`][struct@crate::ShortcutsSection]
807pub trait BoxExt: IsA<Box> + 'static {
808    /// Adds a child at the end.
809    /// ## `child`
810    /// the widget to append
811    #[doc(alias = "gtk_box_append")]
812    fn append(&self, child: &impl IsA<Widget>) {
813        unsafe {
814            ffi::gtk_box_append(
815                self.as_ref().to_glib_none().0,
816                child.as_ref().to_glib_none().0,
817            );
818        }
819    }
820
821    /// Gets the value set by [`set_baseline_child()`][Self::set_baseline_child()].
822    ///
823    /// # Returns
824    ///
825    /// the baseline child
826    #[cfg(feature = "v4_12")]
827    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
828    #[doc(alias = "gtk_box_get_baseline_child")]
829    #[doc(alias = "get_baseline_child")]
830    #[doc(alias = "baseline-child")]
831    fn baseline_child(&self) -> i32 {
832        unsafe { ffi::gtk_box_get_baseline_child(self.as_ref().to_glib_none().0) }
833    }
834
835    /// Gets the value set by [`set_baseline_position()`][Self::set_baseline_position()].
836    ///
837    /// # Returns
838    ///
839    /// the baseline position
840    #[doc(alias = "gtk_box_get_baseline_position")]
841    #[doc(alias = "get_baseline_position")]
842    #[doc(alias = "baseline-position")]
843    fn baseline_position(&self) -> BaselinePosition {
844        unsafe {
845            from_glib(ffi::gtk_box_get_baseline_position(
846                self.as_ref().to_glib_none().0,
847            ))
848        }
849    }
850
851    /// Returns whether the box is homogeneous.
852    ///
853    /// In a homogeneous box all children are the same size.
854    ///
855    /// # Returns
856    ///
857    /// true if the box is homogeneous
858    #[doc(alias = "gtk_box_get_homogeneous")]
859    #[doc(alias = "get_homogeneous")]
860    #[doc(alias = "homogeneous")]
861    fn is_homogeneous(&self) -> bool {
862        unsafe { from_glib(ffi::gtk_box_get_homogeneous(self.as_ref().to_glib_none().0)) }
863    }
864
865    /// Gets the value set by [`set_spacing()`][Self::set_spacing()].
866    ///
867    /// # Returns
868    ///
869    /// spacing between children
870    #[doc(alias = "gtk_box_get_spacing")]
871    #[doc(alias = "get_spacing")]
872    fn spacing(&self) -> i32 {
873        unsafe { ffi::gtk_box_get_spacing(self.as_ref().to_glib_none().0) }
874    }
875
876    /// Inserts a child at a specific position.
877    ///
878    /// The child is added after @sibling in the list of @self children.
879    ///
880    /// If @sibling is `NULL`, the @child is placed at the beginning.
881    /// ## `child`
882    /// the widget to insert
883    /// ## `sibling`
884    /// the sibling after which to insert @child
885    #[doc(alias = "gtk_box_insert_child_after")]
886    fn insert_child_after(&self, child: &impl IsA<Widget>, sibling: Option<&impl IsA<Widget>>) {
887        unsafe {
888            ffi::gtk_box_insert_child_after(
889                self.as_ref().to_glib_none().0,
890                child.as_ref().to_glib_none().0,
891                sibling.map(|p| p.as_ref()).to_glib_none().0,
892            );
893        }
894    }
895
896    /// Adds a child at the beginning.
897    /// ## `child`
898    /// the widget to prepend
899    #[doc(alias = "gtk_box_prepend")]
900    fn prepend(&self, child: &impl IsA<Widget>) {
901        unsafe {
902            ffi::gtk_box_prepend(
903                self.as_ref().to_glib_none().0,
904                child.as_ref().to_glib_none().0,
905            );
906        }
907    }
908
909    /// Removes a child widget from the box.
910    ///
911    /// The child must have been added before with
912    /// [`append()`][Self::append()], [`prepend()`][Self::prepend()], or
913    /// [`insert_child_after()`][Self::insert_child_after()].
914    /// ## `child`
915    /// the child to remove
916    #[doc(alias = "gtk_box_remove")]
917    fn remove(&self, child: &impl IsA<Widget>) {
918        unsafe {
919            ffi::gtk_box_remove(
920                self.as_ref().to_glib_none().0,
921                child.as_ref().to_glib_none().0,
922            );
923        }
924    }
925
926    /// Moves a child to a different position.
927    ///
928    /// The child is moved to the position after @sibling in the list
929    /// of @self children.
930    ///
931    /// If @sibling is `NULL`, the child is placed at the beginning.
932    /// ## `child`
933    /// the widget to move, must be a child of @self
934    /// ## `sibling`
935    /// the sibling to move @child after
936    #[doc(alias = "gtk_box_reorder_child_after")]
937    fn reorder_child_after(&self, child: &impl IsA<Widget>, sibling: Option<&impl IsA<Widget>>) {
938        unsafe {
939            ffi::gtk_box_reorder_child_after(
940                self.as_ref().to_glib_none().0,
941                child.as_ref().to_glib_none().0,
942                sibling.map(|p| p.as_ref()).to_glib_none().0,
943            );
944        }
945    }
946
947    /// Sets the baseline child of a box.
948    ///
949    /// This affects only vertical boxes.
950    /// ## `child`
951    /// a child position, or -1
952    #[cfg(feature = "v4_12")]
953    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
954    #[doc(alias = "gtk_box_set_baseline_child")]
955    #[doc(alias = "baseline-child")]
956    fn set_baseline_child(&self, child: i32) {
957        unsafe {
958            ffi::gtk_box_set_baseline_child(self.as_ref().to_glib_none().0, child);
959        }
960    }
961
962    /// Sets the baseline position of a box.
963    ///
964    /// This affects only horizontal boxes with at least one baseline
965    /// aligned child. If there is more vertical space available than
966    /// requested, and the baseline is not allocated by the parent then
967    /// @position is used to allocate the baseline with respect to the
968    /// extra space available.
969    /// ## `position`
970    /// the baseline position
971    #[doc(alias = "gtk_box_set_baseline_position")]
972    #[doc(alias = "baseline-position")]
973    fn set_baseline_position(&self, position: BaselinePosition) {
974        unsafe {
975            ffi::gtk_box_set_baseline_position(
976                self.as_ref().to_glib_none().0,
977                position.into_glib(),
978            );
979        }
980    }
981
982    /// Sets whether or not all children are given equal space
983    /// in the box.
984    /// ## `homogeneous`
985    /// true to create equal allotments,
986    ///   false for variable allotments
987    #[doc(alias = "gtk_box_set_homogeneous")]
988    #[doc(alias = "homogeneous")]
989    fn set_homogeneous(&self, homogeneous: bool) {
990        unsafe {
991            ffi::gtk_box_set_homogeneous(self.as_ref().to_glib_none().0, homogeneous.into_glib());
992        }
993    }
994
995    /// Sets the number of pixels to place between children.
996    /// ## `spacing`
997    /// the number of pixels to put between children
998    #[doc(alias = "gtk_box_set_spacing")]
999    #[doc(alias = "spacing")]
1000    fn set_spacing(&self, spacing: i32) {
1001        unsafe {
1002            ffi::gtk_box_set_spacing(self.as_ref().to_glib_none().0, spacing);
1003        }
1004    }
1005
1006    #[cfg(feature = "v4_12")]
1007    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1008    #[doc(alias = "baseline-child")]
1009    fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1010        unsafe extern "C" fn notify_baseline_child_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1011            this: *mut ffi::GtkBox,
1012            _param_spec: glib::ffi::gpointer,
1013            f: glib::ffi::gpointer,
1014        ) {
1015            let f: &F = &*(f as *const F);
1016            f(Box::from_glib_borrow(this).unsafe_cast_ref())
1017        }
1018        unsafe {
1019            let f: Box_<F> = Box_::new(f);
1020            connect_raw(
1021                self.as_ptr() as *mut _,
1022                c"notify::baseline-child".as_ptr() as *const _,
1023                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1024                    notify_baseline_child_trampoline::<Self, F> as *const (),
1025                )),
1026                Box_::into_raw(f),
1027            )
1028        }
1029    }
1030
1031    #[doc(alias = "baseline-position")]
1032    fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1033        unsafe extern "C" fn notify_baseline_position_trampoline<
1034            P: IsA<Box>,
1035            F: Fn(&P) + 'static,
1036        >(
1037            this: *mut ffi::GtkBox,
1038            _param_spec: glib::ffi::gpointer,
1039            f: glib::ffi::gpointer,
1040        ) {
1041            let f: &F = &*(f as *const F);
1042            f(Box::from_glib_borrow(this).unsafe_cast_ref())
1043        }
1044        unsafe {
1045            let f: Box_<F> = Box_::new(f);
1046            connect_raw(
1047                self.as_ptr() as *mut _,
1048                c"notify::baseline-position".as_ptr() as *const _,
1049                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1050                    notify_baseline_position_trampoline::<Self, F> as *const (),
1051                )),
1052                Box_::into_raw(f),
1053            )
1054        }
1055    }
1056
1057    #[doc(alias = "homogeneous")]
1058    fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1059        unsafe extern "C" fn notify_homogeneous_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1060            this: *mut ffi::GtkBox,
1061            _param_spec: glib::ffi::gpointer,
1062            f: glib::ffi::gpointer,
1063        ) {
1064            let f: &F = &*(f as *const F);
1065            f(Box::from_glib_borrow(this).unsafe_cast_ref())
1066        }
1067        unsafe {
1068            let f: Box_<F> = Box_::new(f);
1069            connect_raw(
1070                self.as_ptr() as *mut _,
1071                c"notify::homogeneous".as_ptr() as *const _,
1072                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1073                    notify_homogeneous_trampoline::<Self, F> as *const (),
1074                )),
1075                Box_::into_raw(f),
1076            )
1077        }
1078    }
1079
1080    #[doc(alias = "spacing")]
1081    fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1082        unsafe extern "C" fn notify_spacing_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1083            this: *mut ffi::GtkBox,
1084            _param_spec: glib::ffi::gpointer,
1085            f: glib::ffi::gpointer,
1086        ) {
1087            let f: &F = &*(f as *const F);
1088            f(Box::from_glib_borrow(this).unsafe_cast_ref())
1089        }
1090        unsafe {
1091            let f: Box_<F> = Box_::new(f);
1092            connect_raw(
1093                self.as_ptr() as *mut _,
1094                c"notify::spacing".as_ptr() as *const _,
1095                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1096                    notify_spacing_trampoline::<Self, F> as *const (),
1097                )),
1098                Box_::into_raw(f),
1099            )
1100        }
1101    }
1102}
1103
1104impl<O: IsA<Box>> BoxExt for O {}