Description
The GtkBox widget arranges child widgets into a single row or column,
depending upon the value of its “orientation” property. Within
the other dimension, all children are allocated the same size. Of course,
the “halign” and “valign” properties can be used on
the children to influence their allocation.
GtkBox uses a notion of packing. Packing refers
to adding widgets with reference to a particular position in a
GtkContainer. For a GtkBox, there are two reference positions: the
start and the end of the box.
For a vertical GtkBox, the start is defined as the top of the box and
the end is defined as the bottom. For a horizontal GtkBox the start
is defined as the left side and the end is defined as the right side.
Use repeated calls to gtk_box_pack_start() to pack widgets into a
GtkBox from start to end. Use gtk_box_pack_end() to add widgets from
end to start. You may intersperse these calls and add widgets from
both ends of the same GtkBox.
Because GtkBox is a GtkContainer, you may also use gtk_container_add()
to insert widgets into the box, and they will be packed with the default
values for expand and fill child properties. Use gtk_container_remove()
to remove widgets from the GtkBox.
Use gtk_box_set_homogeneous() to specify whether or not all children
of the GtkBox are forced to get the same amount of space.
Use gtk_box_set_spacing() to determine how much space will be
minimally placed between all children in the GtkBox. Note that
spacing is added between the children, while
padding added by gtk_box_pack_start() or gtk_box_pack_end() is added
on either side of the widget it belongs to.
Use gtk_box_reorder_child() to move a GtkBox child to a different
place in the box.
Use gtk_box_set_child_packing() to reset the expand,
fill and padding child properties.
Use gtk_box_query_child_packing() to query these fields.
CSS nodes
GtkBox uses a single CSS node with name box.
In horizontal orientation, the nodes of the children are always arranged
from left to right. So :first-child will always select the leftmost child,
regardless of text direction.
Functions
gtk_box_pack_start ()
void
gtk_box_pack_start (GtkBox *box,
GtkWidget *child,
gboolean expand,
gboolean fill,
guint padding);
Adds child
to box
, packed with reference to the start of box
.
The child
is packed after any other child packed with reference
to the start of box
.
gtk_box_pack_end ()
void
gtk_box_pack_end (GtkBox *box,
GtkWidget *child,
gboolean expand,
gboolean fill,
guint padding);
Adds child
to box
, packed with reference to the end of box
.
The child
is packed after (away from end of) any other child
packed with reference to the end of box
.
gtk_box_get_homogeneous ()
gboolean
gtk_box_get_homogeneous (GtkBox *box);
Returns whether the box is homogeneous (all children are the
same size). See gtk_box_set_homogeneous().
Returns
TRUE if the box is homogeneous.
gtk_box_set_homogeneous ()
void
gtk_box_set_homogeneous (GtkBox *box,
gboolean homogeneous);
Sets the “homogeneous” property of box
, controlling
whether or not all children of box
are given equal space
in the box.
gtk_box_set_spacing ()
void
gtk_box_set_spacing (GtkBox *box,
gint spacing);
Sets the “spacing” property of box
, which is the
number of pixels to place between children of box
.
gtk_box_reorder_child ()
void
gtk_box_reorder_child (GtkBox *box,
GtkWidget *child,
gint position);
Moves child
to a new position
in the list of box
children.
The list contains widgets packed GTK_PACK_START
as well as widgets packed GTK_PACK_END, in the order that these
widgets were added to box
.
A widget’s position in the box
children list determines where
the widget is packed into box
. A child widget at some position
in the list will be packed just after all other widgets of the
same packing type that appear earlier in the list.
gtk_box_set_baseline_position ()
void
gtk_box_set_baseline_position (GtkBox *box,
GtkBaselinePosition position);
Sets the baseline position of a 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.
Since: 3.10
gtk_box_get_center_widget ()
GtkWidget *
gtk_box_get_center_widget (GtkBox *box);
Retrieves the center widget of the box.
Returns
the center widget
or NULL in case no center widget is set.
[transfer none][nullable]
Since: 3.12
gtk_box_set_center_widget ()
void
gtk_box_set_center_widget (GtkBox *box,
GtkWidget *widget);
Sets a center widget; that is a child widget that will be
centered with respect to the full width of the box, even
if the children at either side take up different amounts
of space.
Since: 3.12
Child Property Details
The “expand” child property
“expand” gboolean
Whether the child should receive extra space when the parent grows.
Note that the default value for this property is FALSE for GtkBox,
but GtkHBox, GtkVBox and other subclasses use the old default
of TRUE.
Note: The “hexpand” or “vexpand” properties are the
preferred way to influence whether the child receives extra space, by
setting the child’s expand property corresponding to the box’s orientation.
In contrast to “hexpand”, the expand child property does
not cause the box to expand itself.
Owner: GtkBox
Flags: Read / Write
Default value: FALSE
The “fill” child property
“fill” gboolean
Whether the child should fill extra space or use it as padding.
Note: The “halign” or “valign” properties are the
preferred way to influence whether the child fills available space, by
setting the child’s align property corresponding to the box’s orientation
to GTK_ALIGN_FILL to fill, or to something else to refrain from filling.
Owner: GtkBox
Flags: Read / Write
Default value: TRUE
The “pack-type” child property
“pack-type” GtkPackType
A GtkPackType indicating whether the child is packed with reference to the start or end of the parent.
Owner: GtkBox
Flags: Read / Write
Default value: GTK_PACK_START
The “padding” child property
“padding” guint
Extra space to put between the child and its neighbors, in pixels.
Note: The CSS padding properties are the preferred way to add space among
widgets, by setting the paddings corresponding to the box’s orientation.
Owner: GtkBox
Flags: Read / Write
Allowed values: <= G_MAXINT
Default value: 0
The “position” child property
“position” gint
The index of the child in the parent.
Owner: GtkBox
Flags: Read / Write
Allowed values: >= -1
Default value: 0