A GtkBox manages a row (GtkHBox) or column (GtkVBox) of widgets. For GtkHBox, all the widgets are assigned
the same height; the box's job is to distribute the
available width between them.
GtkHBox optionally uses some of the available width
to leave gaps (called "spacing") between widgets. GtkVBox is identical, but in the
opposite direction (i.e., it distributes available height
rather than width). GtkBox is
an abstract base class;
GtkVBox and GtkHBox can
be used almost entirely via its interface. Boxes are the
most useful container widget.
To create a GtkBox, you use
one of the constructors shown in Figure 2 and
Figure
3. The box constructor functions take two parameters.
If TRUE, homogeneous means that all children
of the box will be allocated the same amount of space.
spacing specifies the
amount of space between each child. There are functions
to change spacing and toggle homogeneity after the box is
created.
There are two basic functions to add a child to a GtkBox; they are shown in Figure 4.
A box can contain two sets of widgets. The first set is
packed at the "start" (top or left) of the box; the
second at the "end" (bottom or right). If you pack three
widgets into the start of a box, the first widget you
pack appears topmost or leftmost; the second follows the
first; and the third appears closest to the center of the
box. If you then pack three widgets into the end of the
same box, the first appears bottommost or rightmost; the
second follows it; and the third appears closest to the
center. With all six widgets packed, the order from
top/left to bottom/right is: 1, 2, 3, 3, 2, 1. Figure 5 shows
this for GtkVBox. Order of
packing is only important within each end of the box;
i.e., we could have alternated packing start and packing
end, with the same results.