Arranges three children in a row, keeping the middle child centered as well as possible.
<picture> <source srcset="centerbox-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkCenterBox" src="centerbox.png"> </picture> To add children to GtkCenterBox, use [methodGtk.CenterBox.set_start_widget], [methodGtk.CenterBox.set_center_widget] and [methodGtk.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 <child> 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 [enumGtk.AccessibleRole.group] role.
Starting from GTK 4.12, GtkCenterBox uses the [enumGtk.AccessibleRole.generic] role.
function "+"
(Widget : access Gtk_Center_Box_Record'Class)
return Gtk.Accessible.Gtk_Accessible
function "+"
(Widget : access Gtk_Center_Box_Record'Class)
return Gtk.Buildable.Gtk_Buildable
function "+"
(Widget : access Gtk_Center_Box_Record'Class)
return Gtk.Constraint_Target.Gtk_Constraint_Target
function "+"
(Widget : access Gtk_Center_Box_Record'Class)
return Gtk.Orientable.Gtk_Orientable
function "-"
(Interf : Gtk.Accessible.Gtk_Accessible)
return Gtk_Center_Box
function "-"
(Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Center_Box
function "-"
(Interf : Gtk.Constraint_Target.Gtk_Constraint_Target)
return Gtk_Center_Box
function "-"
(Interf : Gtk.Orientable.Gtk_Orientable)
return Gtk_Center_Box
procedure Announce
(Self : not null access Gtk_Center_Box_Record;
Message : UTF8_String;
Priority : Gtk.Accessible.Gtk_Accessible_Announcement_Priority)
Baseline_Position_Property : constant Gtk.Enums.Property_Gtk_Baseline_Position;
The position of the baseline aligned widget if extra space is available.
Center_Widget_Property : constant Glib.Properties.Property_Object;
Type: Gtk.Widget.Gtk_Widget The widget that is placed at the center position.
End_Widget_Property : constant Glib.Properties.Property_Object;
Type: Gtk.Widget.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 with respect to the text direction.
function Get_Accessible_Id
(Self : not null access Gtk_Center_Box_Record) return UTF8_String
function Get_Accessible_Parent
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Accessible_Role
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Accessible.Gtk_Accessible_Role
function Get_At_Context
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Atcontext.Gtk_Atcontext
function Get_Baseline_Position
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Enums.Gtk_Baseline_Position
Gets the baseline position of the center box. See [methodGtk.CenterBox.set_baseline_position].
the baseline position
function Get_Bounds
(Self : not null access Gtk_Center_Box_Record;
X : out Glib.Gint;
Y : out Glib.Gint;
Width : out Glib.Gint;
Height : out Glib.Gint) return Boolean
function Get_Center_Widget
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Widget.Gtk_Widget
Gets the center widget.
the center widget. Has transfer-ownership='none'.
function Get_End_Widget
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Widget.Gtk_Widget
Gets the end widget.
the end widget. Has transfer-ownership='none'.
function Get_First_Accessible_Child
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Next_Accessible_Sibling
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Orientation
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Enums.Gtk_Orientation
function Get_Platform_State
(Self : not null access Gtk_Center_Box_Record;
State : Gtk.Accessible.Gtk_Accessible_Platform_State) return Boolean
function Get_Shrink_Center_Last
(Self : not null access Gtk_Center_Box_Record) return Boolean
Gets whether the center widget shrinks after other children. Since: gtk+ 4.12
whether to shrink the center widget after others
function Get_Start_Widget
(Self : not null access Gtk_Center_Box_Record)
return Gtk.Widget.Gtk_Widget
Gets the start widget.
the start widget. Has transfer-ownership='none'.
function Get_Type return Glib.GType
type Gtk_Center_Box is access all Gtk_Center_Box_Record'Class;
function Gtk_Center_Box_New return Gtk_Center_Box
Creates a new GtkCenterBox.
type Gtk_Center_Box_Record is new Gtk_Widget_Record with null record;
procedure Gtk_New (Self : out Gtk_Center_Box)
Creates a new GtkCenterBox. Initialize does nothing if the object was already created with another call to Initialize* or G_New.
package Implements_Gtk_Accessible is new Glib.Types.Implements
(Gtk.Accessible.Gtk_Accessible, Gtk_Center_Box_Record, Gtk_Center_Box);
package Implements_Gtk_Buildable is new Glib.Types.Implements
(Gtk.Buildable.Gtk_Buildable, Gtk_Center_Box_Record, Gtk_Center_Box);
package Implements_Gtk_Constraint_Target is new Glib.Types.Implements
(Gtk.Constraint_Target.Gtk_Constraint_Target, Gtk_Center_Box_Record, Gtk_Center_Box);
package Implements_Gtk_Orientable is new Glib.Types.Implements
(Gtk.Orientable.Gtk_Orientable, Gtk_Center_Box_Record, Gtk_Center_Box);
procedure Initialize (Self : not null access Gtk_Center_Box_Record'Class)
Creates a new GtkCenterBox. Initialize does nothing if the object was already created with another call to Initialize* or G_New.
procedure Reset_Property
(Self : not null access Gtk_Center_Box_Record;
Property : Gtk.Accessible.Gtk_Accessible_Property)
procedure Reset_Relation
(Self : not null access Gtk_Center_Box_Record;
Relation : Gtk.Accessible.Gtk_Accessible_Relation)
procedure Reset_State
(Self : not null access Gtk_Center_Box_Record;
State : Gtk.Accessible.Gtk_Accessible_State)
procedure Set_Accessible_Parent
(Self : not null access Gtk_Center_Box_Record;
Parent : Gtk.Accessible.Gtk_Accessible;
Next_Sibling : Gtk.Accessible.Gtk_Accessible)
procedure Set_Baseline_Position
(Self : not null access Gtk_Center_Box_Record;
Position : Gtk.Enums.Gtk_Baseline_Position)
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 with respect to the extra space available.
the baseline position
procedure Set_Center_Widget
(Self : not null access Gtk_Center_Box_Record;
Child : access Gtk.Widget.Gtk_Widget_Record'Class)
Sets the center widget. To remove the existing center widget, pass NULL.
the new center widget
procedure Set_End_Widget
(Self : not null access Gtk_Center_Box_Record;
Child : access Gtk.Widget.Gtk_Widget_Record'Class)
Sets the end widget. To remove the existing end widget, pass NULL.
the new end widget
procedure Set_Orientation
(Self : not null access Gtk_Center_Box_Record;
Orientation : Gtk.Enums.Gtk_Orientation)
procedure Set_Shrink_Center_Last
(Self : not null access Gtk_Center_Box_Record;
Shrink_Center_Last : Boolean)
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 Shrink_Center_Last is false, start and end widgets keep natural width and the center widget starts shrinking instead. Since: gtk+ 4.12
whether to shrink the center widget after others
procedure Set_Start_Widget
(Self : not null access Gtk_Center_Box_Record;
Child : access Gtk.Widget.Gtk_Widget_Record'Class)
Sets the start widget. To remove the existing start widget, pass NULL.
the new start widget
Shrink_Center_Last_Property : constant Glib.Properties.Property_Boolean;
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 false, start and end widgets keep natural width and the center widget starts shrinking instead.
Start_Widget_Property : constant Glib.Properties.Property_Object;
Type: Gtk.Widget.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 with respect to the text direction.
procedure Update_Next_Accessible_Sibling
(Self : not null access Gtk_Center_Box_Record;
New_Sibling : Gtk.Accessible.Gtk_Accessible)
procedure Update_Platform_State
(Self : not null access Gtk_Center_Box_Record;
State : Gtk.Accessible.Gtk_Accessible_Platform_State)