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, ffi,
8};
9use glib::{
10 prelude::*,
11 signal::{SignalHandlerId, connect_raw},
12 translate::*,
13};
14use std::boxed::Box as Box_;
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 | Writable
70 ///
71 ///
72 /// #### `homogeneous`
73 /// Readable | Writable
74 ///
75 ///
76 /// #### `spacing`
77 /// Readable | Writable
78 /// <details><summary><h4>Container</h4></summary>
79 ///
80 ///
81 /// #### `border-width`
82 /// Readable | Writable
83 ///
84 ///
85 /// #### `child`
86 /// Writable
87 ///
88 ///
89 /// #### `resize-mode`
90 /// Readable | Writable
91 /// </details>
92 /// <details><summary><h4>Widget</h4></summary>
93 ///
94 ///
95 /// #### `app-paintable`
96 /// Readable | Writable
97 ///
98 ///
99 /// #### `can-default`
100 /// Readable | Writable
101 ///
102 ///
103 /// #### `can-focus`
104 /// Readable | Writable
105 ///
106 ///
107 /// #### `composite-child`
108 /// Readable
109 ///
110 ///
111 /// #### `double-buffered`
112 /// Whether the widget is double buffered.
113 ///
114 /// Readable | Writable
115 ///
116 ///
117 /// #### `events`
118 /// Readable | Writable
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 | 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 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
133 /// GtkComboBox) implemented this property individually.
134 ///
135 /// Readable | Writable
136 ///
137 ///
138 /// #### `halign`
139 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
140 ///
141 /// Readable | Writable
142 ///
143 ///
144 /// #### `has-default`
145 /// Readable | Writable
146 ///
147 ///
148 /// #### `has-focus`
149 /// Readable | Writable
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 | Writable
164 ///
165 ///
166 /// #### `height-request`
167 /// Readable | Writable
168 ///
169 ///
170 /// #### `hexpand`
171 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
172 ///
173 /// Readable | Writable
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 | Writable
180 ///
181 ///
182 /// #### `is-focus`
183 /// Readable | Writable
184 ///
185 ///
186 /// #### `margin`
187 /// Sets all four sides' margin at once. If read, returns max
188 /// margin on any side.
189 ///
190 /// Readable | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
253 ///
254 ///
255 /// #### `name`
256 /// Readable | Writable
257 ///
258 ///
259 /// #### `no-show-all`
260 /// Readable | Writable
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 | Writable
270 ///
271 ///
272 /// #### `parent`
273 /// Readable | Writable
274 ///
275 ///
276 /// #### `receives-default`
277 /// Readable | Writable
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 | Writable
289 ///
290 ///
291 /// #### `style`
292 /// The style of the widget, which contains information about how it will look (colors, etc).
293 ///
294 /// Readable | Writable
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 | Writable
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 | Writable
327 ///
328 ///
329 /// #### `valign`
330 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
331 ///
332 /// Readable | Writable
333 ///
334 ///
335 /// #### `vexpand`
336 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
337 ///
338 /// Readable | Writable
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 | Writable
345 ///
346 ///
347 /// #### `visible`
348 /// Readable | Writable
349 ///
350 ///
351 /// #### `width-request`
352 /// Readable | Writable
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 | Writable
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 assert_initialized_main_thread!();
747 self.builder.build()
748 }
749}
750
751/// Trait containing all [`struct@Box`] methods.
752///
753/// # Implementors
754///
755/// [`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]
756pub trait BoxExt: IsA<Box> + 'static {
757 /// Gets the value set by [`set_baseline_position()`][Self::set_baseline_position()].
758 ///
759 /// # Returns
760 ///
761 /// the baseline position
762 #[doc(alias = "gtk_box_get_baseline_position")]
763 #[doc(alias = "get_baseline_position")]
764 #[doc(alias = "baseline-position")]
765 fn baseline_position(&self) -> BaselinePosition {
766 unsafe {
767 from_glib(ffi::gtk_box_get_baseline_position(
768 self.as_ref().to_glib_none().0,
769 ))
770 }
771 }
772
773 /// Retrieves the center widget of the box.
774 ///
775 /// # Returns
776 ///
777 /// the center widget
778 /// or [`None`] in case no center widget is set.
779 #[doc(alias = "gtk_box_get_center_widget")]
780 #[doc(alias = "get_center_widget")]
781 fn center_widget(&self) -> Option<Widget> {
782 unsafe {
783 from_glib_none(ffi::gtk_box_get_center_widget(
784 self.as_ref().to_glib_none().0,
785 ))
786 }
787 }
788
789 /// Returns whether the box is homogeneous (all children are the
790 /// same size). See [`set_homogeneous()`][Self::set_homogeneous()].
791 ///
792 /// # Returns
793 ///
794 /// [`true`] if the box is homogeneous.
795 #[doc(alias = "gtk_box_get_homogeneous")]
796 #[doc(alias = "get_homogeneous")]
797 #[doc(alias = "homogeneous")]
798 fn is_homogeneous(&self) -> bool {
799 unsafe { from_glib(ffi::gtk_box_get_homogeneous(self.as_ref().to_glib_none().0)) }
800 }
801
802 /// Gets the value set by [`set_spacing()`][Self::set_spacing()].
803 ///
804 /// # Returns
805 ///
806 /// spacing between children
807 #[doc(alias = "gtk_box_get_spacing")]
808 #[doc(alias = "get_spacing")]
809 fn spacing(&self) -> i32 {
810 unsafe { ffi::gtk_box_get_spacing(self.as_ref().to_glib_none().0) }
811 }
812
813 /// Adds `child` to `self`, packed with reference to the end of `self`.
814 /// The `child` is packed after (away from end of) any other child
815 /// packed with reference to the end of `self`.
816 /// ## `child`
817 /// the [`Widget`][crate::Widget] to be added to `self`
818 /// ## `expand`
819 /// [`true`] if the new child is to be given extra space allocated
820 /// to `self`. The extra space will be divided evenly between all children
821 /// of `self` that use this option
822 /// ## `fill`
823 /// [`true`] if space given to `child` by the `expand` option is
824 /// actually allocated to `child`, rather than just padding it. This
825 /// parameter has no effect if `expand` is set to [`false`]. A child is
826 /// always allocated the full height of a horizontal [`Box`][crate::Box] and the full width
827 /// of a vertical [`Box`][crate::Box]. This option affects the other dimension
828 /// ## `padding`
829 /// extra space in pixels to put between this child and its
830 /// neighbors, over and above the global amount specified by
831 /// [`spacing`][struct@crate::Box#spacing] property. If `child` is a widget at one of the
832 /// reference ends of `self`, then `padding` pixels are also put between
833 /// `child` and the reference edge of `self`
834 #[doc(alias = "gtk_box_pack_end")]
835 fn pack_end(&self, child: &impl IsA<Widget>, expand: bool, fill: bool, padding: u32) {
836 unsafe {
837 ffi::gtk_box_pack_end(
838 self.as_ref().to_glib_none().0,
839 child.as_ref().to_glib_none().0,
840 expand.into_glib(),
841 fill.into_glib(),
842 padding,
843 );
844 }
845 }
846
847 /// Adds `child` to `self`, packed with reference to the start of `self`.
848 /// The `child` is packed after any other child packed with reference
849 /// to the start of `self`.
850 /// ## `child`
851 /// the [`Widget`][crate::Widget] to be added to `self`
852 /// ## `expand`
853 /// [`true`] if the new child is to be given extra space allocated
854 /// to `self`. The extra space will be divided evenly between all children
855 /// that use this option
856 /// ## `fill`
857 /// [`true`] if space given to `child` by the `expand` option is
858 /// actually allocated to `child`, rather than just padding it. This
859 /// parameter has no effect if `expand` is set to [`false`]. A child is
860 /// always allocated the full height of a horizontal [`Box`][crate::Box] and the full width
861 /// of a vertical [`Box`][crate::Box]. This option affects the other dimension
862 /// ## `padding`
863 /// extra space in pixels to put between this child and its
864 /// neighbors, over and above the global amount specified by
865 /// [`spacing`][struct@crate::Box#spacing] property. If `child` is a widget at one of the
866 /// reference ends of `self`, then `padding` pixels are also put between
867 /// `child` and the reference edge of `self`
868 #[doc(alias = "gtk_box_pack_start")]
869 fn pack_start(&self, child: &impl IsA<Widget>, expand: bool, fill: bool, padding: u32) {
870 unsafe {
871 ffi::gtk_box_pack_start(
872 self.as_ref().to_glib_none().0,
873 child.as_ref().to_glib_none().0,
874 expand.into_glib(),
875 fill.into_glib(),
876 padding,
877 );
878 }
879 }
880
881 /// Obtains information about how `child` is packed into `self`.
882 /// ## `child`
883 /// the [`Widget`][crate::Widget] of the child to query
884 ///
885 /// # Returns
886 ///
887 ///
888 /// ## `expand`
889 /// pointer to return location for expand child
890 /// property
891 ///
892 /// ## `fill`
893 /// pointer to return location for fill child
894 /// property
895 ///
896 /// ## `padding`
897 /// pointer to return location for padding
898 /// child property
899 ///
900 /// ## `pack_type`
901 /// pointer to return location for pack-type
902 /// child property
903 #[doc(alias = "gtk_box_query_child_packing")]
904 fn query_child_packing(&self, child: &impl IsA<Widget>) -> (bool, bool, u32, PackType) {
905 unsafe {
906 let mut expand = std::mem::MaybeUninit::uninit();
907 let mut fill = std::mem::MaybeUninit::uninit();
908 let mut padding = std::mem::MaybeUninit::uninit();
909 let mut pack_type = std::mem::MaybeUninit::uninit();
910 ffi::gtk_box_query_child_packing(
911 self.as_ref().to_glib_none().0,
912 child.as_ref().to_glib_none().0,
913 expand.as_mut_ptr(),
914 fill.as_mut_ptr(),
915 padding.as_mut_ptr(),
916 pack_type.as_mut_ptr(),
917 );
918 (
919 from_glib(expand.assume_init()),
920 from_glib(fill.assume_init()),
921 padding.assume_init(),
922 from_glib(pack_type.assume_init()),
923 )
924 }
925 }
926
927 /// Moves `child` to a new `position` in the list of `self` children.
928 /// The list contains widgets packed [`PackType::Start`][crate::PackType::Start]
929 /// as well as widgets packed [`PackType::End`][crate::PackType::End], in the order that these
930 /// widgets were added to `self`.
931 ///
932 /// A widget’s position in the `self` children list determines where
933 /// the widget is packed into `self`. A child widget at some position
934 /// in the list will be packed just after all other widgets of the
935 /// same packing type that appear earlier in the list.
936 /// ## `child`
937 /// the [`Widget`][crate::Widget] to move
938 /// ## `position`
939 /// the new position for `child` in the list of children
940 /// of `self`, starting from 0. If negative, indicates the end of
941 /// the list
942 #[doc(alias = "gtk_box_reorder_child")]
943 fn reorder_child(&self, child: &impl IsA<Widget>, position: i32) {
944 unsafe {
945 ffi::gtk_box_reorder_child(
946 self.as_ref().to_glib_none().0,
947 child.as_ref().to_glib_none().0,
948 position,
949 );
950 }
951 }
952
953 /// Sets the baseline position of a box. This affects
954 /// only horizontal boxes with at least one baseline aligned
955 /// child. If there is more vertical space available than requested,
956 /// and the baseline is not allocated by the parent then
957 /// `position` is used to allocate the baseline wrt the
958 /// extra space available.
959 /// ## `position`
960 /// a [`BaselinePosition`][crate::BaselinePosition]
961 #[doc(alias = "gtk_box_set_baseline_position")]
962 #[doc(alias = "baseline-position")]
963 fn set_baseline_position(&self, position: BaselinePosition) {
964 unsafe {
965 ffi::gtk_box_set_baseline_position(
966 self.as_ref().to_glib_none().0,
967 position.into_glib(),
968 );
969 }
970 }
971
972 /// Sets a center widget; that is a child widget that will be
973 /// centered with respect to the full width of the box, even
974 /// if the children at either side take up different amounts
975 /// of space.
976 /// ## `widget`
977 /// the widget to center
978 #[doc(alias = "gtk_box_set_center_widget")]
979 fn set_center_widget(&self, widget: Option<&impl IsA<Widget>>) {
980 unsafe {
981 ffi::gtk_box_set_center_widget(
982 self.as_ref().to_glib_none().0,
983 widget.map(|p| p.as_ref()).to_glib_none().0,
984 );
985 }
986 }
987
988 /// Sets the way `child` is packed into `self`.
989 /// ## `child`
990 /// the [`Widget`][crate::Widget] of the child to set
991 /// ## `expand`
992 /// the new value of the expand child property
993 /// ## `fill`
994 /// the new value of the fill child property
995 /// ## `padding`
996 /// the new value of the padding child property
997 /// ## `pack_type`
998 /// the new value of the pack-type child property
999 #[doc(alias = "gtk_box_set_child_packing")]
1000 fn set_child_packing(
1001 &self,
1002 child: &impl IsA<Widget>,
1003 expand: bool,
1004 fill: bool,
1005 padding: u32,
1006 pack_type: PackType,
1007 ) {
1008 unsafe {
1009 ffi::gtk_box_set_child_packing(
1010 self.as_ref().to_glib_none().0,
1011 child.as_ref().to_glib_none().0,
1012 expand.into_glib(),
1013 fill.into_glib(),
1014 padding,
1015 pack_type.into_glib(),
1016 );
1017 }
1018 }
1019
1020 /// Sets the [`homogeneous`][struct@crate::Box#homogeneous] property of `self`, controlling
1021 /// whether or not all children of `self` are given equal space
1022 /// in the box.
1023 /// ## `homogeneous`
1024 /// a boolean value, [`true`] to create equal allotments,
1025 /// [`false`] for variable allotments
1026 #[doc(alias = "gtk_box_set_homogeneous")]
1027 #[doc(alias = "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 #[doc(alias = "spacing")]
1040 fn set_spacing(&self, spacing: i32) {
1041 unsafe {
1042 ffi::gtk_box_set_spacing(self.as_ref().to_glib_none().0, spacing);
1043 }
1044 }
1045
1046 fn child_expands<T: IsA<crate::Widget>>(&self, item: &T) -> bool {
1047 crate::prelude::ContainerExtManual::child_property(
1048 self.as_ref(),
1049 &item.clone().upcast(),
1050 "expand",
1051 )
1052 }
1053
1054 fn set_child_expand<T: IsA<crate::Widget>>(&self, item: &T, expand: bool) {
1055 crate::prelude::ContainerExtManual::child_set_property(
1056 self.as_ref(),
1057 &item.clone().upcast(),
1058 "expand",
1059 &expand,
1060 )
1061 }
1062
1063 fn child_fills<T: IsA<crate::Widget>>(&self, item: &T) -> bool {
1064 crate::prelude::ContainerExtManual::child_property(
1065 self.as_ref(),
1066 &item.clone().upcast(),
1067 "fill",
1068 )
1069 }
1070
1071 fn set_child_fill<T: IsA<crate::Widget>>(&self, item: &T, fill: bool) {
1072 crate::prelude::ContainerExtManual::child_set_property(
1073 self.as_ref(),
1074 &item.clone().upcast(),
1075 "fill",
1076 &fill,
1077 )
1078 }
1079
1080 #[doc(alias = "child.pack-type")]
1081 fn child_pack_type<T: IsA<crate::Widget>>(&self, item: &T) -> PackType {
1082 crate::prelude::ContainerExtManual::child_property(
1083 self.as_ref(),
1084 &item.clone().upcast(),
1085 "pack-type",
1086 )
1087 }
1088
1089 #[doc(alias = "child.pack-type")]
1090 fn set_child_pack_type<T: IsA<crate::Widget>>(&self, item: &T, pack_type: PackType) {
1091 crate::prelude::ContainerExtManual::child_set_property(
1092 self.as_ref(),
1093 &item.clone().upcast(),
1094 "pack-type",
1095 &pack_type,
1096 )
1097 }
1098
1099 fn child_padding<T: IsA<crate::Widget>>(&self, item: &T) -> u32 {
1100 crate::prelude::ContainerExtManual::child_property(
1101 self.as_ref(),
1102 &item.clone().upcast(),
1103 "padding",
1104 )
1105 }
1106
1107 fn set_child_padding<T: IsA<crate::Widget>>(&self, item: &T, padding: u32) {
1108 crate::prelude::ContainerExtManual::child_set_property(
1109 self.as_ref(),
1110 &item.clone().upcast(),
1111 "padding",
1112 &padding,
1113 )
1114 }
1115
1116 fn child_position<T: IsA<crate::Widget>>(&self, item: &T) -> i32 {
1117 crate::prelude::ContainerExtManual::child_property(
1118 self.as_ref(),
1119 &item.clone().upcast(),
1120 "position",
1121 )
1122 }
1123
1124 fn set_child_position<T: IsA<crate::Widget>>(&self, item: &T, position: i32) {
1125 crate::prelude::ContainerExtManual::child_set_property(
1126 self.as_ref(),
1127 &item.clone().upcast(),
1128 "position",
1129 &position,
1130 )
1131 }
1132
1133 #[doc(alias = "baseline-position")]
1134 fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1135 unsafe extern "C" fn notify_baseline_position_trampoline<
1136 P: IsA<Box>,
1137 F: Fn(&P) + 'static,
1138 >(
1139 this: *mut ffi::GtkBox,
1140 _param_spec: glib::ffi::gpointer,
1141 f: glib::ffi::gpointer,
1142 ) {
1143 unsafe {
1144 let f: &F = &*(f as *const F);
1145 f(Box::from_glib_borrow(this).unsafe_cast_ref())
1146 }
1147 }
1148 unsafe {
1149 let f: Box_<F> = Box_::new(f);
1150 connect_raw(
1151 self.as_ptr() as *mut _,
1152 c"notify::baseline-position".as_ptr(),
1153 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1154 notify_baseline_position_trampoline::<Self, F> as *const (),
1155 )),
1156 Box_::into_raw(f),
1157 )
1158 }
1159 }
1160
1161 #[doc(alias = "homogeneous")]
1162 fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1163 unsafe extern "C" fn notify_homogeneous_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1164 this: *mut ffi::GtkBox,
1165 _param_spec: glib::ffi::gpointer,
1166 f: glib::ffi::gpointer,
1167 ) {
1168 unsafe {
1169 let f: &F = &*(f as *const F);
1170 f(Box::from_glib_borrow(this).unsafe_cast_ref())
1171 }
1172 }
1173 unsafe {
1174 let f: Box_<F> = Box_::new(f);
1175 connect_raw(
1176 self.as_ptr() as *mut _,
1177 c"notify::homogeneous".as_ptr(),
1178 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1179 notify_homogeneous_trampoline::<Self, F> as *const (),
1180 )),
1181 Box_::into_raw(f),
1182 )
1183 }
1184 }
1185
1186 #[doc(alias = "spacing")]
1187 fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1188 unsafe extern "C" fn notify_spacing_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
1189 this: *mut ffi::GtkBox,
1190 _param_spec: glib::ffi::gpointer,
1191 f: glib::ffi::gpointer,
1192 ) {
1193 unsafe {
1194 let f: &F = &*(f as *const F);
1195 f(Box::from_glib_borrow(this).unsafe_cast_ref())
1196 }
1197 }
1198 unsafe {
1199 let f: Box_<F> = Box_::new(f);
1200 connect_raw(
1201 self.as_ptr() as *mut _,
1202 c"notify::spacing".as_ptr(),
1203 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1204 notify_spacing_trampoline::<Self, F> as *const (),
1205 )),
1206 Box_::into_raw(f),
1207 )
1208 }
1209 }
1210}
1211
1212impl<O: IsA<Box>> BoxExt for O {}