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