1Theory of Operation

A table panel provides a panel that aligns its children on a grid. This is implemented by a new class table-panel% that specializes the panel% class.

Currently, the absolute dimensions of the grid are specified, as well as the major axis.

There is a fair amount of flexibility provided in terms of specifying how column widths and row heights can be adjusted (stretched) in response to resizing of the panel. This can be specified absolutely—that is, columns (or rows) can always be stretched or never be stretched, or based on the characteristics of the cells—that is, columns (or rows) can be stretched if any, or all, or its cells can be stretched.

The table panel’s behavior is specified by the container-size and place-children methods. The container-size method computes the size of the grid based on the minimum sizes of each of the grids columns and rows (as well as any border and spacing specified). The place-children method computes the column widths and row heights based on the actual space available, adjusting them as necessary, and places each child in the grid based on the alignment option of the grid, the child’s location (row and column) in the grid, and the child’s stretchability (horizontal and vertical).

If the 'border style is specified, the window is created with a thin border (only in this case, the client size of the panel may be less than its total size). If style includes 'deleted, then the panel is created as hidden, and it does not affect its parent’s geometry; the panel can be made active later by calling parent’s add-child method.

For information about the enabled argument, see window<%>. For information about the horiz-margin and vert-margin arguments, see subarea<%>. For information about the border, spacing, and alignment arguments, see area-container<%>. For information about the min-width, min-height, stretchable-width, and stretchable-height arguments, see area<%>.

The dimensions argument specifies the number of rows and columns in the grid. There should be rows × columns children of the panel. The default is '(11).

The major-axis argument specifies the major axis for in the grid. This specifies the order in which the children are placed in the grid. If major-axis is 'row, then all of the columns in a row are placed before moving to the next row. If major-axis is 'column, then all of the rows for a column are placed before moving to the next column. The default is 'row.

For example, if dimensions is '(22), then there should be four children, say, child0, child1, child2, and child3. If major-axis is 'row, then child0 is placed in row0column0—the upper left cell, child1 is placed in row0column1—the upper right cell, child2 is placed in row1column0—the lower left cell, and child2 is placed in row1column1—the lower right cell. If major-axis is 'column, then child0 is placed in row0column0—the upper left cell, child1 is placed in row1column0—the lower left cell, child2 is placed in row0column1—the upper right cell, and child2 is placed in row1column1—the lower right cell.

The column-stretchability and row-stretchability arguments specify how column widths and row heights can be adjusted when additional space (above the minimum sizes) is available:

#t—Column widths (or row heights) are always stretchable.

'any—The width of a column (or the height of a row) is stretchable if any of its rows is stretchable horizontally (or any of its columns are stretchable vertically). That is, a column or row can stretch if any of its cells can take advantage of the extra space.

'every—The width of a column (or the height of a row) is stretchable if all of its rows is stretchable horizontally (or all of its columns are stretchable vertically). That is, a column or row can stretch if all of its cells can take advantage of the extra space.

The following image shows the output as originally sized by PLT Scheme based on the minimum sizes of the elements.

The next image shows the output after resizing the frame. The upper left panel specifies both row and column stretchability, the upper right panel specifies only column stretchability, the lower left panel specifies only row stretchability, and the lower right panel specified neither column nor row stretchability.

Note that the outer 2 × 2 table panel specifies the default column and row stretchability of 'any, which, in this case, allows its columns and rows to stretch because (at least one of) each of its columns and rows can stretch.

4Issues and To Do

It isn’t really necessary to specify both the number of rows and the number of columns. All we need to know is the major axis and the dimensionality of the minor axis. The dimensionality of the major axis can be determined using the number of children and the dimensionality of the minor axis—(ceiling(/(lengthchildren)n-minor-axis)). We could allow one of the dimensions to be specified by a placeholder. For example, (dimensions ’(* 3)) would specify a row major table with each row having three columns. Similar changes would have to be made for get-dimensions and set-dimensions. We would also have to add some error checking to make sure the major axis is compatible with the dimensions.