gtk/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 Align, BaselinePosition, Buildable, Container, Orientable, Orientation, PackType, ResizeMode,
7 Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::{boxed::Box as Box_, fmt, mem, mem::transmute};
15
16glib::wrapper! {
17 /// The GtkBox widget arranges child widgets into a single row or column,
18 /// depending upon the value of its [`orientation`][struct@crate::Orientable#orientation] property. Within
19 /// the other dimension, all children are allocated the same size. Of course,
20 /// the [`halign`][struct@crate::Widget#halign] and [`valign`][struct@crate::Widget#valign] properties can be used on
21 /// the children to influence their allocation.
22 ///
23 /// GtkBox uses a notion of packing. Packing refers
24 /// to adding widgets with reference to a particular position in a
25 /// [`Container`][crate::Container]. For a GtkBox, there are two reference positions: the
26 /// start and the end of the box.
27 /// For a vertical [`Box`][crate::Box], the start is defined as the top of the box and
28 /// the end is defined as the bottom. For a horizontal [`Box`][crate::Box] the start
29 /// is defined as the left side and the end is defined as the right side.
30 ///
31 /// Use repeated calls to [`BoxExt::pack_start()`][crate::prelude::BoxExt::pack_start()] to pack widgets into a
32 /// GtkBox from start to end. Use [`BoxExt::pack_end()`][crate::prelude::BoxExt::pack_end()] to add widgets from
33 /// end to start. You may intersperse these calls and add widgets from
34 /// both ends of the same GtkBox.
35 ///
36 /// Because GtkBox is a [`Container`][crate::Container], you may also use [`ContainerExt::add()`][crate::prelude::ContainerExt::add()]
37 /// to insert widgets into the box, and they will be packed with the default
38 /// values for expand and fill child properties. Use [`ContainerExt::remove()`][crate::prelude::ContainerExt::remove()]
39 /// to remove widgets from the GtkBox.
40 ///
41 /// Use [`BoxExt::set_homogeneous()`][crate::prelude::BoxExt::set_homogeneous()] to specify whether or not all children
42 /// of the GtkBox are forced to get the same amount of space.
43 ///
44 /// Use [`BoxExt::set_spacing()`][crate::prelude::BoxExt::set_spacing()] to determine how much space will be
45 /// minimally placed between all children in the GtkBox. Note that
46 /// spacing is added between the children, while
47 /// padding added by [`BoxExt::pack_start()`][crate::prelude::BoxExt::pack_start()] or [`BoxExt::pack_end()`][crate::prelude::BoxExt::pack_end()] is added
48 /// on either side of the widget it belongs to.
49 ///
50 /// Use [`BoxExt::reorder_child()`][crate::prelude::BoxExt::reorder_child()] to move a GtkBox child to a different
51 /// place in the box.
52 ///
53 /// Use [`BoxExt::set_child_packing()`][crate::prelude::BoxExt::set_child_packing()] to reset the expand,
54 /// fill and padding child properties.
55 /// Use [`BoxExt::query_child_packing()`][crate::prelude::BoxExt::query_child_packing()] to query these fields.
56 ///
57 /// # CSS nodes
58 ///
59 /// GtkBox uses a single CSS node with name box.
60 ///
61 /// In horizontal orientation, the nodes of the children are always arranged
62 /// from left to right. So :first-child will always select the leftmost child,
63 /// regardless of text direction.
64 ///
65 /// ## Properties
66 ///
67 ///
68 /// #### `baseline-position`
69 /// Readable | Writeable
70 ///
71 ///
72 /// #### `homogeneous`
73 /// Readable | Writeable
74 ///
75 ///
76 /// #### `spacing`
77 /// Readable | Writeable
78 /// <details><summary><h4>Container</h4></summary>
79 ///
80 ///
81 /// #### `border-width`
82 /// Readable | Writeable
83 ///
84 ///
85 /// #### `child`
86 /// Writeable
87 ///
88 ///
89 /// #### `resize-mode`
90 /// Readable | Writeable
91 /// </details>
92 /// <details><summary><h4>Widget</h4></summary>
93 ///
94 ///
95 /// #### `app-paintable`
96 /// Readable | Writeable
97 ///
98 ///
99 /// #### `can-default`
100 /// Readable | Writeable
101 ///
102 ///
103 /// #### `can-focus`
104 /// Readable | Writeable
105 ///
106 ///
107 /// #### `composite-child`
108 /// Readable
109 ///
110 ///
111 /// #### `double-buffered`
112 /// Whether the widget is double buffered.
113 ///
114 /// Readable | Writeable
115 ///
116 ///
117 /// #### `events`
118 /// Readable | Writeable
119 ///
120 ///
121 /// #### `expand`
122 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
123 ///
124 /// Readable | Writeable
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 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
133 /// GtkComboBox) implemented this property individually.
134 ///
135 /// Readable | Writeable
136 ///
137 ///
138 /// #### `halign`
139 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
140 ///
141 /// Readable | Writeable
142 ///
143 ///
144 /// #### `has-default`
145 /// Readable | Writeable
146 ///
147 ///
148 /// #### `has-focus`
149 /// Readable | Writeable
150 ///
151 ///
152 /// #### `has-tooltip`
153 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
154 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
155 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
156 /// whether it will provide a tooltip or not.
157 ///
158 /// Note that setting this property to [`true`] for the first time will change
159 /// the event masks of the GdkWindows of this widget to include leave-notify
160 /// and motion-notify events. This cannot and will not be undone when the
161 /// property is set to [`false`] again.
162 ///
163 /// Readable | Writeable
164 ///
165 ///
166 /// #### `height-request`
167 /// Readable | Writeable
168 ///
169 ///
170 /// #### `hexpand`
171 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
172 ///
173 /// Readable | Writeable
174 ///
175 ///
176 /// #### `hexpand-set`
177 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
178 ///
179 /// Readable | Writeable
180 ///
181 ///
182 /// #### `is-focus`
183 /// Readable | Writeable
184 ///
185 ///
186 /// #### `margin`
187 /// Sets all four sides' margin at once. If read, returns max
188 /// margin on any side.
189 ///
190 /// Readable | Writeable
191 ///
192 ///
193 /// #### `margin-bottom`
194 /// Margin on bottom side of widget.
195 ///
196 /// This property adds margin outside of the widget's normal size
197 /// request, the margin will be added in addition to the size from
198 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
199 ///
200 /// Readable | Writeable
201 ///
202 ///
203 /// #### `margin-end`
204 /// Margin on end of widget, horizontally. This property supports
205 /// left-to-right and right-to-left text directions.
206 ///
207 /// This property adds margin outside of the widget's normal size
208 /// request, the margin will be added in addition to the size from
209 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
210 ///
211 /// Readable | Writeable
212 ///
213 ///
214 /// #### `margin-left`
215 /// Margin on left side of widget.
216 ///
217 /// This property adds margin outside of the widget's normal size
218 /// request, the margin will be added in addition to the size from
219 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
220 ///
221 /// Readable | Writeable
222 ///
223 ///
224 /// #### `margin-right`
225 /// Margin on right side of widget.
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 | Writeable
232 ///
233 ///
234 /// #### `margin-start`
235 /// Margin on start of widget, horizontally. This property supports
236 /// left-to-right and right-to-left text directions.
237 ///
238 /// This property adds margin outside of the widget's normal size
239 /// request, the margin will be added in addition to the size from
240 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
241 ///
242 /// Readable | Writeable
243 ///
244 ///
245 /// #### `margin-top`
246 /// Margin on top side of widget.
247 ///
248 /// This property adds margin outside of the widget's normal size
249 /// request, the margin will be added in addition to the size from
250 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
251 ///
252 /// Readable | Writeable
253 ///
254 ///
255 /// #### `name`
256 /// Readable | Writeable
257 ///
258 ///
259 /// #### `no-show-all`
260 /// Readable | Writeable
261 ///
262 ///
263 /// #### `opacity`
264 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
265 /// more details about window opacity.
266 ///
267 /// Before 3.8 this was only available in GtkWindow
268 ///
269 /// Readable | Writeable
270 ///
271 ///
272 /// #### `parent`
273 /// Readable | Writeable
274 ///
275 ///
276 /// #### `receives-default`
277 /// Readable | Writeable
278 ///
279 ///
280 /// #### `scale-factor`
281 /// The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
282 /// more details about widget scaling.
283 ///
284 /// Readable
285 ///
286 ///
287 /// #### `sensitive`
288 /// Readable | Writeable
289 ///
290 ///
291 /// #### `style`
292 /// The style of the widget, which contains information about how it will look (colors, etc).
293 ///
294 /// Readable | Writeable
295 ///
296 ///
297 /// #### `tooltip-markup`
298 /// Sets the text of tooltip to be the given string, which is marked up
299 /// with the [Pango text markup language][PangoMarkupFormat].
300 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
301 ///
302 /// This is a convenience property which will take care of getting the
303 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
304 /// will automatically be set to [`true`] and there will be taken care of
305 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
306 ///
307 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
308 /// are set, the last one wins.
309 ///
310 /// Readable | Writeable
311 ///
312 ///
313 /// #### `tooltip-text`
314 /// Sets the text of tooltip to be the given string.
315 ///
316 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
317 ///
318 /// This is a convenience property which will take care of getting the
319 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
320 /// will automatically be set to [`true`] and there will be taken care of
321 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
322 ///
323 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
324 /// are set, the last one wins.
325 ///
326 /// Readable | Writeable
327 ///
328 ///
329 /// #### `valign`
330 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
331 ///
332 /// Readable | Writeable
333 ///
334 ///
335 /// #### `vexpand`
336 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
337 ///
338 /// Readable | Writeable
339 ///
340 ///
341 /// #### `vexpand-set`
342 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
343 ///
344 /// Readable | Writeable
345 ///
346 ///
347 /// #### `visible`
348 /// Readable | Writeable
349 ///
350 ///
351 /// #### `width-request`
352 /// Readable | Writeable
353 ///
354 ///
355 /// #### `window`
356 /// The widget's window if it is realized, [`None`] otherwise.
357 ///
358 /// Readable
359 /// </details>
360 /// <details><summary><h4>Orientable</h4></summary>
361 ///
362 ///
363 /// #### `orientation`
364 /// The orientation of the orientable.
365 ///
366 /// Readable | Writeable
367 /// </details>
368 ///
369 /// # Implements
370 ///
371 /// [`BoxExt`][trait@crate::prelude::BoxExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
372 #[doc(alias = "GtkBox")]
373 pub struct Box(Object<ffi::GtkBox, ffi::GtkBoxClass>) @extends Container, Widget, @implements Buildable, Orientable;
374
375 match fn {
376 type_ => || ffi::gtk_box_get_type(),
377 }
378}
379
380impl Box {
381 pub const NONE: Option<&'static Box> = None;
382
383 /// Creates a new [`Box`][crate::Box].
384 /// ## `orientation`
385 /// the box’s orientation.
386 /// ## `spacing`
387 /// the number of pixels to place by default between children.
388 ///
389 /// # Returns
390 ///
391 /// a new [`Box`][crate::Box].
392 #[doc(alias = "gtk_box_new")]
393 pub fn new(orientation: Orientation, spacing: i32) -> Box {
394 assert_initialized_main_thread!();
395 unsafe {
396 Widget::from_glib_none(ffi::gtk_box_new(orientation.into_glib(), spacing)).unsafe_cast()
397 }
398 }
399
400 // rustdoc-stripper-ignore-next
401 /// Creates a new builder-pattern struct instance to construct [`Box`] objects.
402 ///
403 /// This method returns an instance of [`BoxBuilder`](crate::builders::BoxBuilder) which can be used to create [`Box`] objects.
404 pub fn builder() -> BoxBuilder {
405 BoxBuilder::new()
406 }
407}
408
409impl Default for Box {
410 fn default() -> Self {
411 glib::object::Object::new::<Self>()
412 }
413}
414
415// rustdoc-stripper-ignore-next
416/// A [builder-pattern] type to construct [`Box`] objects.
417///
418/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
419#[must_use = "The builder must be built to be used"]
420pub struct BoxBuilder {
421 builder: glib::object::ObjectBuilder<'static, Box>,
422}
423
424impl BoxBuilder {
425 fn new() -> Self {
426 Self {
427 builder: glib::object::Object::builder(),
428 }
429 }
430
431 pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
432 Self {
433 builder: self
434 .builder
435 .property("baseline-position", baseline_position),
436 }
437 }
438
439 pub fn homogeneous(self, homogeneous: bool) -> Self {
440 Self {
441 builder: self.builder.property("homogeneous", homogeneous),
442 }
443 }
444
445 pub fn spacing(self, spacing: i32) -> Self {
446 Self {
447 builder: self.builder.property("spacing", spacing),
448 }
449 }
450
451 pub fn border_width(self, border_width: u32) -> Self {
452 Self {
453 builder: self.builder.property("border-width", border_width),
454 }
455 }
456
457 pub fn child(self, child: &impl IsA<Widget>) -> Self {
458 Self {
459 builder: self.builder.property("child", child.clone().upcast()),
460 }
461 }
462
463 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
464 Self {
465 builder: self.builder.property("resize-mode", resize_mode),
466 }
467 }
468
469 pub fn app_paintable(self, app_paintable: bool) -> Self {
470 Self {
471 builder: self.builder.property("app-paintable", app_paintable),
472 }
473 }
474
475 pub fn can_default(self, can_default: bool) -> Self {
476 Self {
477 builder: self.builder.property("can-default", can_default),
478 }
479 }
480
481 pub fn can_focus(self, can_focus: bool) -> Self {
482 Self {
483 builder: self.builder.property("can-focus", can_focus),
484 }
485 }
486
487 pub fn events(self, events: gdk::EventMask) -> Self {
488 Self {
489 builder: self.builder.property("events", events),
490 }
491 }
492
493 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
494 pub fn expand(self, expand: bool) -> Self {
495 Self {
496 builder: self.builder.property("expand", expand),
497 }
498 }
499
500 /// Whether the widget should grab focus when it is clicked with the mouse.
501 ///
502 /// This property is only relevant for widgets that can take focus.
503 ///
504 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
505 /// GtkComboBox) implemented this property individually.
506 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
507 Self {
508 builder: self.builder.property("focus-on-click", focus_on_click),
509 }
510 }
511
512 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
513 pub fn halign(self, halign: Align) -> Self {
514 Self {
515 builder: self.builder.property("halign", halign),
516 }
517 }
518
519 pub fn has_default(self, has_default: bool) -> Self {
520 Self {
521 builder: self.builder.property("has-default", has_default),
522 }
523 }
524
525 pub fn has_focus(self, has_focus: bool) -> Self {
526 Self {
527 builder: self.builder.property("has-focus", has_focus),
528 }
529 }
530
531 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
532 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
533 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
534 /// whether it will provide a tooltip or not.
535 ///
536 /// Note that setting this property to [`true`] for the first time will change
537 /// the event masks of the GdkWindows of this widget to include leave-notify
538 /// and motion-notify events. This cannot and will not be undone when the
539 /// property is set to [`false`] again.
540 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
541 Self {
542 builder: self.builder.property("has-tooltip", has_tooltip),
543 }
544 }
545
546 pub fn height_request(self, height_request: i32) -> Self {
547 Self {
548 builder: self.builder.property("height-request", height_request),
549 }
550 }
551
552 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
553 pub fn hexpand(self, hexpand: bool) -> Self {
554 Self {
555 builder: self.builder.property("hexpand", hexpand),
556 }
557 }
558
559 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
560 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
561 Self {
562 builder: self.builder.property("hexpand-set", hexpand_set),
563 }
564 }
565
566 pub fn is_focus(self, is_focus: bool) -> Self {
567 Self {
568 builder: self.builder.property("is-focus", is_focus),
569 }
570 }
571
572 /// Sets all four sides' margin at once. If read, returns max
573 /// margin on any side.
574 pub fn margin(self, margin: i32) -> Self {
575 Self {
576 builder: self.builder.property("margin", margin),
577 }
578 }
579
580 /// Margin on bottom side of widget.
581 ///
582 /// This property adds margin outside of the widget's normal size
583 /// request, the margin will be added in addition to the size from
584 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
585 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
586 Self {
587 builder: self.builder.property("margin-bottom", margin_bottom),
588 }
589 }
590
591 /// Margin on end of widget, horizontally. This property supports
592 /// left-to-right and right-to-left text directions.
593 ///
594 /// This property adds margin outside of the widget's normal size
595 /// request, the margin will be added in addition to the size from
596 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
597 pub fn margin_end(self, margin_end: i32) -> Self {
598 Self {
599 builder: self.builder.property("margin-end", margin_end),
600 }
601 }
602
603 /// Margin on start of widget, horizontally. This property supports
604 /// left-to-right and right-to-left text directions.
605 ///
606 /// This property adds margin outside of the widget's normal size
607 /// request, the margin will be added in addition to the size from
608 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
609 pub fn margin_start(self, margin_start: i32) -> Self {
610 Self {
611 builder: self.builder.property("margin-start", margin_start),
612 }
613 }
614
615 /// Margin on top side of widget.
616 ///
617 /// This property adds margin outside of the widget's normal size
618 /// request, the margin will be added in addition to the size from
619 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
620 pub fn margin_top(self, margin_top: i32) -> Self {
621 Self {
622 builder: self.builder.property("margin-top", margin_top),
623 }
624 }
625
626 pub fn name(self, name: impl Into<glib::GString>) -> Self {
627 Self {
628 builder: self.builder.property("name", name.into()),
629 }
630 }
631
632 pub fn no_show_all(self, no_show_all: bool) -> Self {
633 Self {
634 builder: self.builder.property("no-show-all", no_show_all),
635 }
636 }
637
638 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
639 /// more details about window opacity.
640 ///
641 /// Before 3.8 this was only available in GtkWindow
642 pub fn opacity(self, opacity: f64) -> Self {
643 Self {
644 builder: self.builder.property("opacity", opacity),
645 }
646 }
647
648 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
649 Self {
650 builder: self.builder.property("parent", parent.clone().upcast()),
651 }
652 }
653
654 pub fn receives_default(self, receives_default: bool) -> Self {
655 Self {
656 builder: self.builder.property("receives-default", receives_default),
657 }
658 }
659
660 pub fn sensitive(self, sensitive: bool) -> Self {
661 Self {
662 builder: self.builder.property("sensitive", sensitive),
663 }
664 }
665
666 /// Sets the text of tooltip to be the given string, which is marked up
667 /// with the [Pango text markup language][PangoMarkupFormat].
668 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
669 ///
670 /// This is a convenience property which will take care of getting the
671 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
672 /// will automatically be set to [`true`] and there will be taken care of
673 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
674 ///
675 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
676 /// are set, the last one wins.
677 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
678 Self {
679 builder: self
680 .builder
681 .property("tooltip-markup", tooltip_markup.into()),
682 }
683 }
684
685 /// Sets the text of tooltip to be the given string.
686 ///
687 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
688 ///
689 /// This is a convenience property which will take care of getting the
690 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
691 /// will automatically be set to [`true`] and there will be taken care of
692 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
693 ///
694 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
695 /// are set, the last one wins.
696 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
697 Self {
698 builder: self.builder.property("tooltip-text", tooltip_text.into()),
699 }
700 }
701
702 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
703 pub fn valign(self, valign: Align) -> Self {
704 Self {
705 builder: self.builder.property("valign", valign),
706 }
707 }
708
709 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
710 pub fn vexpand(self, vexpand: bool) -> Self {
711 Self {
712 builder: self.builder.property("vexpand", vexpand),
713 }
714 }
715
716 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
717 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
718 Self {
719 builder: self.builder.property("vexpand-set", vexpand_set),
720 }
721 }
722
723 pub fn visible(self, visible: bool) -> Self {
724 Self {
725 builder: self.builder.property("visible", visible),
726 }
727 }
728
729 pub fn width_request(self, width_request: i32) -> Self {
730 Self {
731 builder: self.builder.property("width-request", width_request),
732 }
733 }
734
735 /// The orientation of the orientable.
736 pub fn orientation(self, orientation: Orientation) -> Self {
737 Self {
738 builder: self.builder.property("orientation", orientation),
739 }
740 }
741
742 // rustdoc-stripper-ignore-next
743 /// Build the [`Box`].
744 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
745 pub fn build(self) -> Box {
746 self.builder.build()
747 }
748}
749
750mod sealed {
751 pub trait Sealed {}
752 impl<T: super::IsA<super::Box>> Sealed for T {}
753}
754
755/// Trait containing all [`struct@Box`] methods.
756///
757/// # Implementors
758///
759/// [`AppChooserWidget`][struct@crate::AppChooserWidget], [`Box`][struct@crate::Box], [`ButtonBox`][struct@crate::ButtonBox], [`ColorChooserWidget`][struct@crate::ColorChooserWidget], [`FileChooserButton`][struct@crate::FileChooserButton], [`FileChooserWidget`][struct@crate::FileChooserWidget], [`FontChooserWidget`][struct@crate::FontChooserWidget], [`InfoBar`][struct@crate::InfoBar], [`RecentChooserWidget`][struct@crate::RecentChooserWidget], [`ShortcutLabel`][struct@crate::ShortcutLabel], [`ShortcutsGroup`][struct@crate::ShortcutsGroup], [`ShortcutsSection`][struct@crate::ShortcutsSection], [`ShortcutsShortcut`][struct@crate::ShortcutsShortcut], [`StackSwitcher`][struct@crate::StackSwitcher], [`Statusbar`][struct@crate::Statusbar]
760pub trait BoxExt: IsA<Box> + sealed::Sealed + 'static {
761 /// Gets the value set by [`set_baseline_position()`][Self::set_baseline_position()].
762 ///
763 /// # Returns
764 ///
765 /// the baseline position
766 #[doc(alias = "gtk_box_get_baseline_position")]
767 #[doc(alias = "get_baseline_position")]
768 fn baseline_position(&self) -> BaselinePosition {
769 unsafe {
770 from_glib(ffi::gtk_box_get_baseline_position(
771 self.as_ref().to_glib_none().0,
772 ))
773 }
774 }
775
776 /// Retrieves the center widget of the box.
777 ///
778 /// # Returns
779 ///
780 /// the center widget
781 /// or [`None`] in case no center widget is set.
782 #[doc(alias = "gtk_box_get_center_widget")]
783 #[doc(alias = "get_center_widget")]
784 fn center_widget(&self) -> Option<Widget> {
785 unsafe {
786 from_glib_none(ffi::gtk_box_get_center_widget(
787 self.as_ref().to_glib_none().0,
788 ))
789 }
790 }
791
792 /// Returns whether the box is homogeneous (all children are the
793 /// same size). See [`set_homogeneous()`][Self::set_homogeneous()].
794 ///
795 /// # Returns
796 ///
797 /// [`true`] if the box is homogeneous.
798 #[doc(alias = "gtk_box_get_homogeneous")]
799 #[doc(alias = "get_homogeneous")]
800 fn is_homogeneous(&self) -> bool {
801 unsafe { from_glib(ffi::gtk_box_get_homogeneous(self.as_ref().to_glib_none().0)) }
802 }
803
804 /// Gets the value set by [`set_spacing()`][Self::set_spacing()].
805 ///
806 /// # Returns
807 ///
808 /// spacing between children
809 #[doc(alias = "gtk_box_get_spacing")]
810 #[doc(alias = "get_spacing")]
811 fn spacing(&self) -> i32 {
812 unsafe { ffi::gtk_box_get_spacing(self.as_ref().to_glib_none().0) }
813 }
814
815 /// Adds `child` to `self`, packed with reference to the end of `self`.
816 /// The `child` is packed after (away from end of) any other child
817 /// packed with reference to the end of `self`.
818 /// ## `child`
819 /// the [`Widget`][crate::Widget] to be added to `self`
820 /// ## `expand`
821 /// [`true`] if the new child is to be given extra space allocated
822 /// to `self`. The extra space will be divided evenly between all children
823 /// of `self` that use this option
824 /// ## `fill`
825 /// [`true`] if space given to `child` by the `expand` option is
826 /// actually allocated to `child`, rather than just padding it. This
827 /// parameter has no effect if `expand` is set to [`false`]. A child is
828 /// always allocated the full height of a horizontal [`Box`][crate::Box] and the full width
829 /// of a vertical [`Box`][crate::Box]. This option affects the other dimension
830 /// ## `padding`
831 /// extra space in pixels to put between this child and its
832 /// neighbors, over and above the global amount specified by
833 /// [`spacing`][struct@crate::Box#spacing] property. If `child` is a widget at one of the
834 /// reference ends of `self`, then `padding` pixels are also put between
835 /// `child` and the reference edge of `self`
836 #[doc(alias = "gtk_box_pack_end")]
837 fn pack_end(&self, child: &impl IsA<Widget>, expand: bool, fill: bool, padding: u32) {
838 unsafe {
839 ffi::gtk_box_pack_end(
840 self.as_ref().to_glib_none().0,
841 child.as_ref().to_glib_none().0,
842 expand.into_glib(),
843 fill.into_glib(),
844 padding,
845 );
846 }
847 }
848
849 /// Adds `child` to `self`, packed with reference to the start of `self`.
850 /// The `child` is packed after any other child packed with reference
851 /// to the start of `self`.
852 /// ## `child`
853 /// the [`Widget`][crate::Widget] to be added to `self`
854 /// ## `expand`
855 /// [`true`] if the new child is to be given extra space allocated
856 /// to `self`. The extra space will be divided evenly between all children
857 /// that use this option
858 /// ## `fill`
859 /// [`true`] if space given to `child` by the `expand` option is
860 /// actually allocated to `child`, rather than just padding it. This
861 /// parameter has no effect if `expand` is set to [`false`]. A child is
862 /// always allocated the full height of a horizontal [`Box`][crate::Box] and the full width
863 /// of a vertical [`Box`][crate::Box]. This option affects the other dimension
864 /// ## `padding`
865 /// extra space in pixels to put between this child and its
866 /// neighbors, over and above the global amount specified by
867 /// [`spacing`][struct@crate::Box#spacing] property. If `child` is a widget at one of the
868 /// reference ends of `self`, then `padding` pixels are also put between
869 /// `child` and the reference edge of `self`
870 #[doc(alias = "gtk_box_pack_start")]
871 fn pack_start(&self, child: &impl IsA<Widget>, expand: bool, fill: bool, padding: u32) {
872 unsafe {
873 ffi::gtk_box_pack_start(
874 self.as_ref().to_glib_none().0,
875 child.as_ref().to_glib_none().0,
876 expand.into_glib(),
877 fill.into_glib(),
878 padding,
879 );
880 }
881 }
882
883 /// Obtains information about how `child` is packed into `self`.
884 /// ## `child`
885 /// the [`Widget`][crate::Widget] of the child to query
886 ///
887 /// # Returns
888 ///
889 ///
890 /// ## `expand`
891 /// pointer to return location for expand child
892 /// property
893 ///
894 /// ## `fill`
895 /// pointer to return location for fill child
896 /// property
897 ///
898 /// ## `padding`
899 /// pointer to return location for padding
900 /// child property
901 ///
902 /// ## `pack_type`
903 /// pointer to return location for pack-type
904 /// child property
905 #[doc(alias = "gtk_box_query_child_packing")]
906 fn query_child_packing(&self, child: &impl IsA<Widget>) -> (bool, bool, u32, PackType) {
907 unsafe {
908 let mut expand = mem::MaybeUninit::uninit();
909 let mut fill = mem::MaybeUninit::uninit();
910 let mut padding = mem::MaybeUninit::uninit();
911 let mut pack_type = mem::MaybeUninit::uninit();
912 ffi::gtk_box_query_child_packing(
913 self.as_ref().to_glib_none().0,
914 child.as_ref().to_glib_none().0,
915 expand.as_mut_ptr(),
916 fill.as_mut_ptr(),
917 padding.as_mut_ptr(),
918 pack_type.as_mut_ptr(),
919 );
920 (
921 from_glib(expand.assume_init()),
922 from_glib(fill.assume_init()),
923 padding.assume_init(),
924 from_glib(pack_type.assume_init()),
925 )
926 }
927 }
928
929 /// Moves `child` to a new `position` in the list of `self` children.
930 /// The list contains widgets packed [`PackType::Start`][crate::PackType::Start]
931 /// as well as widgets packed [`PackType::End`][crate::PackType::End], in the order that these
932 /// widgets were added to `self`.
933 ///
934 /// A widget’s position in the `self` children list determines where
935 /// the widget is packed into `self`. A child widget at some position
936 /// in the list will be packed just after all other widgets of the
937 /// same packing type that appear earlier in the list.
938 /// ## `child`
939 /// the [`Widget`][crate::Widget] to move
940 /// ## `position`
941 /// the new position for `child` in the list of children
942 /// of `self`, starting from 0. If negative, indicates the end of
943 /// the list
944 #[doc(alias = "gtk_box_reorder_child")]
945 fn reorder_child(&self, child: &impl IsA<Widget>, position: i32) {
946 unsafe {
947 ffi::gtk_box_reorder_child(
948 self.as_ref().to_glib_none().0,
949 child.as_ref().to_glib_none().0,
950 position,
951 );
952 }
953 }
954
955 /// Sets the baseline position of a box. This affects
956 /// only horizontal boxes with at least one baseline aligned
957 /// child. If there is more vertical space available than requested,
958 /// and the baseline is not allocated by the parent then
959 /// `position` is used to allocate the baseline wrt the
960 /// extra space available.
961 /// ## `position`
962 /// a [`BaselinePosition`][crate::BaselinePosition]
963 #[doc(alias = "gtk_box_set_baseline_position")]
964 fn set_baseline_position(&self, position: BaselinePosition) {
965 unsafe {
966 ffi::gtk_box_set_baseline_position(
967 self.as_ref().to_glib_none().0,
968 position.into_glib(),
969 );
970 }
971 }
972
973 /// Sets a center widget; that is a child widget that will be
974 /// centered with respect to the full width of the box, even
975 /// if the children at either side take up different amounts
976 /// of space.
977 /// ## `widget`
978 /// the widget to center
979 #[doc(alias = "gtk_box_set_center_widget")]
980 fn set_center_widget(&self, widget: Option<&impl IsA<Widget>>) {
981 unsafe {
982 ffi::gtk_box_set_center_widget(
983 self.as_ref().to_glib_none().0,
984 widget.map(|p| p.as_ref()).to_glib_none().0,
985 );
986 }
987 }
988
989 /// Sets the way `child` is packed into `self`.
990 /// ## `child`
991 /// the [`Widget`][crate::Widget] of the child to set
992 /// ## `expand`
993 /// the new value of the expand child property
994 /// ## `fill`
995 /// the new value of the fill child property
996 /// ## `padding`
997 /// the new value of the padding child property
998 /// ## `pack_type`
999 /// the new value of the pack-type child property
1000 #[doc(alias = "gtk_box_set_child_packing")]
1001 fn set_child_packing(
1002 &self,
1003 child: &impl IsA<Widget>,
1004 expand: bool,
1005 fill: bool,
1006 padding: u32,
1007 pack_type: PackType,
1008 ) {
1009 unsafe {
1010 ffi::gtk_box_set_child_packing(
1011 self.as_ref().to_glib_none().0,
1012 child.as_ref().to_glib_none().0,
1013 expand.into_glib(),
1014 fill.into_glib(),
1015 padding,
1016 pack_type.into_glib(),
1017 );
1018 }
1019 }
1020
1021 /// Sets the [`homogeneous`][struct@crate::Box#homogeneous] property of `self`, controlling
1022 /// whether or not all children of `self` are given equal space
1023 /// in the box.
1024 /// ## `homogeneous`
1025 /// a boolean value, [`true`] to create equal allotments,
1026 /// [`false`] for variable allotments
1027 #[doc(alias = "gtk_box_set_homogeneous")]
1028 fn set_homogeneous(&self, homogeneous: bool) {
1029 unsafe {
1030 ffi::gtk_box_set_homogeneous(self.as_ref().to_glib_none().0, homogeneous.into_glib());
1031 }
1032 }
1033
1034 /// Sets the [`spacing`][struct@crate::Box#spacing] property of `self`, which is the
1035 /// number of pixels to place between children of `self`.
1036 /// ## `spacing`
1037 /// the number of pixels to put between children
1038 #[doc(alias = "gtk_box_set_spacing")]
1039 fn set_spacing(&self, spacing: i32) {
1040 unsafe {
1041 ffi::gtk_box_set_spacing(self.as_ref().to_glib_none().0, spacing);
1042 }
1043 }
1044
1045 fn child_expands<T: IsA<crate::Widget>>(&self, item: &T) -> bool {
1046 crate::prelude::ContainerExtManual::child_property(
1047 self.as_ref(),
1048 &item.clone().upcast(),
1049 "expand",
1050 )
1051 }
1052
1053 fn set_child_expand<T: IsA<crate::Widget>>(&self, item: &T, expand: bool) {
1054 crate::prelude::ContainerExtManual::child_set_property(
1055 self.as_ref(),
1056 &item.clone().upcast(),
1057 "expand",
1058 &expand,
1059 )
1060 }
1061
1062 fn child_fills<T: IsA<crate::Widget>>(&self, item: &T) -> bool {
1063 crate::prelude::ContainerExtManual::child_property(
1064 self.as_ref(),
1065 &item.clone().upcast(),
1066 "fill",
1067 )
1068 }
1069
1070 fn set_child_fill<T: IsA<crate::Widget>>(&self, item: &T, fill: bool) {
1071 crate::prelude::ContainerExtManual::child_set_property(
1072 self.as_ref(),
1073 &item.clone().upcast(),
1074 "fill",
1075 &fill,
1076 )
1077 }
1078
1079 #[doc(alias = "child.pack-type")]
1080 fn child_pack_type<T: IsA<crate::Widget>>(&self, item: &T) -> PackType {
1081 crate::prelude::ContainerExtManual::child_property(
1082 self.as_ref(),
1083 &item.clone().upcast(),
1084 "pack-type",
1085 )
1086 }
1087
1088 #[doc(alias = "child.pack-type")]
1089 fn set_child_pack_type<T: IsA<crate::Widget>>(&self, item: &T, pack_type: PackType) {
1090 crate::prelude::ContainerExtManual::child_set_property(
1091 self.as_ref(),
1092 &item.clone().upcast(),
1093 "pack-type",
1094 &pack_type,
1095 )
1096 }
1097
1098 fn child_padding<T: IsA<crate::Widget>>(&self, item: &T) -> u32 {
1099 crate::prelude::ContainerExtManual::child_property(
1100 self.as_ref(),
1101 &item.clone().upcast(),
1102 "padding",
1103 )
1104 }
1105
1106 fn set_child_padding<T: IsA<crate::Widget>>(&self, item: &T, padding: u32) {
1107 crate::prelude::ContainerExtManual::child_set_property(
1108 self.as_ref(),
1109 &item.clone().upcast(),
1110 "padding",
1111 &padding,
1112 )
1113 }
1114
1115 fn child_position<T: IsA<crate::Widget>>(&self, item: &T) -> i32 {
1116 crate::prelude::ContainerExtManual::child_property(
1117 self.as_ref(),
1118 &item.clone().upcast(),
1119 "position",
1120 )
1121 }
1122
1123 fn set_child_position<T: IsA<crate::Widget>>(&self, item: &T, position: i32) {
1124 crate::prelude::ContainerExtManual::child_set_property(
1125 self.as_ref(),
1126 &item.clone().upcast(),
1127 "position",
1128 &position,
1129 )
1130 }
1131
1132 #[doc(alias = "baseline-position")]
1133 fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1134 unsafe extern "C" fn notify_baseline_position_trampoline<
1135 P: IsA<Box>,
1136 F: Fn(&P) + 'static,
1137 >(
1138 this: *mut ffi::GtkBox,
1139 _param_spec: glib::ffi::gpointer,
1140 f: glib::ffi::gpointer,
1141 ) {
1142 let f: &F = &*(f as *const F);
1143 f(Box::from_glib_borrow(this).unsafe_cast_ref())
1144 }
1145 unsafe {
1146 let f: Box_<F> = Box_::new(f);
1147 connect_raw(
1148 self.as_ptr() as *mut _,
1149 b"notify::baseline-position\0".as_ptr() as *const _,
1150 Some(transmute::<_, unsafe extern "C" fn()>(
1151 notify_baseline_position_trampoline::<Self, F> as *const (),
1152 )),
1153 Box_::into_raw(f),
1154 )
1155 }
1156 }
1157
1158 #[doc(alias = "homogeneous")]
1159 fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1160 unsafe extern "C" fn notify_homogeneous_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1161 this: *mut ffi::GtkBox,
1162 _param_spec: glib::ffi::gpointer,
1163 f: glib::ffi::gpointer,
1164 ) {
1165 let f: &F = &*(f as *const F);
1166 f(Box::from_glib_borrow(this).unsafe_cast_ref())
1167 }
1168 unsafe {
1169 let f: Box_<F> = Box_::new(f);
1170 connect_raw(
1171 self.as_ptr() as *mut _,
1172 b"notify::homogeneous\0".as_ptr() as *const _,
1173 Some(transmute::<_, unsafe extern "C" fn()>(
1174 notify_homogeneous_trampoline::<Self, F> as *const (),
1175 )),
1176 Box_::into_raw(f),
1177 )
1178 }
1179 }
1180
1181 #[doc(alias = "spacing")]
1182 fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1183 unsafe extern "C" fn notify_spacing_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1184 this: *mut ffi::GtkBox,
1185 _param_spec: glib::ffi::gpointer,
1186 f: glib::ffi::gpointer,
1187 ) {
1188 let f: &F = &*(f as *const F);
1189 f(Box::from_glib_borrow(this).unsafe_cast_ref())
1190 }
1191 unsafe {
1192 let f: Box_<F> = Box_::new(f);
1193 connect_raw(
1194 self.as_ptr() as *mut _,
1195 b"notify::spacing\0".as_ptr() as *const _,
1196 Some(transmute::<_, unsafe extern "C" fn()>(
1197 notify_spacing_trampoline::<Self, F> as *const (),
1198 )),
1199 Box_::into_raw(f),
1200 )
1201 }
1202 }
1203}
1204
1205impl<O: IsA<Box>> BoxExt for O {}
1206
1207impl fmt::Display for Box {
1208 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1209 f.write_str("Box")
1210 }
1211}