The second most common layout container is GtkTable.
GtkTable divides a region into cells; you can assign
each child widget to a rectangle made up of one or more
cells. You can think of
GtkTable as a sheet of graph paper (with more
flexibility---the grid lines do not have to be
equidistant, though they can be).
GtkTable comes with the usual
constructor, and some functions to attach children to it;
these are shown in Figure 12. When
creating a table, you specify the number of cells you
plan to use; this is purely for efficiency. The table
will automatically grow if you place children in cells
outside its current area. Like boxes, tables can be
homogeneous or not.
The first two arguments to
gtk_table_attach() are the table and the child to
place in the table. The next four specify which grid
lines should form the bounding box of the child. Grid
lines are numbered from the top left (northwest) corner
of the table, starting with 0; so a 2 by 3 table will
have vertical lines 0, 1, 2 and horizontal lines 0,1,2,3.
The last two arguments are the amount of padding to put
on the left-right sides of the child (xpadding) and the top-bottom (ypadding). This is analagous to
padding in boxes.
The GtkAttachOptions
arguments require some explanation. Here's a summary of
possible values. The values are bitmasks, so more than
one can be specified by or-ing them together.
-
GTK_EXPAND specifies
that this section of the table will expand to fit
available space, much like the expand option when packing
boxes.
-
GTK_FILL specifies
that the child widget will expand to fill available
space. Important only if
GTK_EXPAND is set, because GTK_EXPAND permits extra space to
exist.
-
GTK_SHRINK determines
what will happen if there is insufficient space to
meet the child's size request. If GTK_SHRINK is set, the child is
given a smaller allocation which reflects available
space---i.e., the table shrinks the child. If it
isn't set, the child is given its requested size;
this may result in overlapping children within the
table, and children will be "chopped off" at the
table edges (because they'll try to draw outside the
table's
GdkWindow).
It's possible to set spacing between rows and columns, in
addition to padding around particular children; the terms
"spacing" and "padding" mean the same thing with respect
to tables and boxes. See
gtk/gtktable.h for a complete list of available GtkTable functions.