Box Packing
The program we are to see implements a panel containing ten buttons
labeled with digits from 0 to 9, inclusive. If a button is clicked, then
the digit appearing in its label is printed out (onto the stdout channel).
In terms of the layout of buttons, there four rows in the panel; the first
three rows contain three buttons each and the last row contains only one
button; the buttons are labeled with 1, 2, 3, 4, 5, 6, 7, 8, 9, and 0 when
enumerated in row-major mode.
The following function button_create creates a button
with a given label:
When clicked, the created button prints out the string contained in
its label onto the stdout channel.
The following function row_create creates a horizontal
box (H-box) of buttons:
Each button in the created H-box is created by calling
button_create on the corresponding string in the given argument
of
row_create, which is a list of strings. Note that the
function
gtk_box_pack_start packs a given widget into an H-box
at the leftmost available position. There is another function
gtk_box_pack_end that packs a given widget into an H-box at the
rightmost available position. These two functions can also be called to
pack widgets into vertical boxes.
The following function thePanel_create creates
a panel of ten buttons that are labeled with digits:
where the values
row0,
row1, and
row2 have the following bindings when
thePanel_create
is called:
The function
thePanel_create returns a vertical box (V-box).
In its body, the function
gtk_box_pack_start is called to pack
four H-boxes into the returned V-box. When called to pack a widget into a
V-box,
gtk_box_pack_start chooses the topmost available position
for the widget.
The entirety of the presented code can be found in
chap_boxpack.dats, and there is a
Makefile available for compiling the file.