:right-sidebar: True CenterBox =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: CenterBox(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gtk.Widget`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gtk.Accessible`, :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.ConstraintTarget`, :class:`~gi.repository.Gtk.Orientable` ``GtkCenterBox`` arranges three children in a row, keeping the middle child centered as well as possible. .. image:: https://docs.gtk.org/gtk4/centerbox.png To add children to ``GtkCenterBox``, use :obj:`~gi.repository.Gtk.CenterBox.set_start_widget`, :obj:`~gi.repository.Gtk.CenterBox.set_center_widget` and :obj:`~gi.repository.Gtk.CenterBox.set_end_widget`. The sizing and positioning of children can be influenced with the align and expand properties of the children. GtkCenterBox as GtkBuildable ---------------------------- The ``GtkCenterBox`` implementation of the ``GtkBuildable`` interface supports placing children in the 3 positions by specifying “start”, “center” or “end” as the “type” attribute of a ```` element. CSS nodes --------- ``GtkCenterBox`` uses a single CSS node with the name “box”, The first child of the ``GtkCenterBox`` will be allocated depending on the text direction, i.e. in left-to-right layouts it will be allocated on the left and in right-to-left layouts on the right. In vertical orientation, the nodes of the children are arranged from top to bottom. Accessibility ------------- Until GTK 4.10, ``GtkCenterBox`` used the ``GTK_ACCESSIBLE_ROLE_GROUP`` role. Starting from GTK 4.12, ``GtkCenterBox`` uses the ``GTK_ACCESSIBLE_ROLE_GENERIC`` role. Constructors ------------ .. rst-class:: interim-class .. class:: CenterBox :no-index: .. classmethod:: new() -> ~gi.repository.Gtk.Widget Creates a new ``GtkCenterBox``. Methods ------- .. rst-class:: interim-class .. class:: CenterBox :no-index: .. method:: get_baseline_position() -> ~gi.repository.Gtk.BaselinePosition Gets the value set by :func:`~gi.repository.Gtk.CenterBox.set_baseline_position`. .. method:: get_center_widget() -> ~gi.repository.Gtk.Widget | None Gets the center widget, or :const:`None` if there is none. .. method:: get_end_widget() -> ~gi.repository.Gtk.Widget | None Gets the end widget, or :const:`None` if there is none. .. method:: get_shrink_center_last() -> bool Gets whether ``self`` shrinks the center widget after other children. .. versionadded:: 4.12 .. method:: get_start_widget() -> ~gi.repository.Gtk.Widget | None Gets the start widget, or :const:`None` if there is none. .. method:: set_baseline_position(position: ~gi.repository.Gtk.BaselinePosition) -> None Sets the baseline position of a center box. This affects only horizontal boxes with at least one baseline aligned child. If there is more vertical space available than requested, and the baseline is not allocated by the parent then ``position`` is used to allocate the baseline wrt. the extra space available. :param position: a ``GtkBaselinePosition`` .. method:: set_center_widget(child: ~gi.repository.Gtk.Widget | None = None) -> None Sets the center widget. To remove the existing center widget, pass :const:`None`. :param child: the new center widget .. method:: set_end_widget(child: ~gi.repository.Gtk.Widget | None = None) -> None Sets the end widget. To remove the existing end widget, pass :const:`None`. :param child: the new end widget .. method:: set_shrink_center_last(shrink_center_last: bool) -> None Sets whether to shrink the center widget after other children. By default, when there's no space to give all three children their natural widths, the start and end widgets start shrinking and the center child keeps natural width until they reach minimum width. If set to ``FALSE``, start and end widgets keep natural width and the center widget starts shrinking instead. .. versionadded:: 4.12 :param shrink_center_last: whether to shrink the center widget after others .. method:: set_start_widget(child: ~gi.repository.Gtk.Widget | None = None) -> None Sets the start widget. To remove the existing start widget, pass :const:`None`. :param child: the new start widget Properties ---------- .. rst-class:: interim-class .. class:: CenterBox :no-index: .. attribute:: props.baseline_position :type: ~gi.repository.Gtk.BaselinePosition The position of the baseline aligned widget if extra space is available. .. attribute:: props.center_widget :type: ~gi.repository.Gtk.Widget The widget that is placed at the center position. .. versionadded:: 4.10 .. attribute:: props.end_widget :type: ~gi.repository.Gtk.Widget The widget that is placed at the end position. In vertical orientation, the end position is at the bottom. In horizontal orientation, the end position is at the trailing edge wrt. to the text direction. .. versionadded:: 4.10 .. attribute:: props.shrink_center_last :type: bool Whether to shrink the center widget after other children. By default, when there's no space to give all three children their natural widths, the start and end widgets start shrinking and the center child keeps natural width until they reach minimum width. If set to ``FALSE``, start and end widgets keep natural width and the center widget starts shrinking instead. .. versionadded:: 4.12 .. attribute:: props.start_widget :type: ~gi.repository.Gtk.Widget The widget that is placed at the start position. In vertical orientation, the start position is at the top. In horizontal orientation, the start position is at the leading edge wrt. to the text direction. .. versionadded:: 4.10