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