// compute the preferred size of the fixed columns
int ii = 0;
for (Element<?> elem : elems) {
int col = ii % columns, row = ii / columns;
if (elem.isVisible() && _columns[col]._weight == 0) {
IDimension psize = preferredSize(elem, hintX, hintY);
metrics.rowHeights[row] = Math.max(metrics.rowHeights[row], psize.height());
// Elements which stretch across multiple columns shouldn't force their first column
// to have a large size. Ideally, this should somehow force the sum of the columns
// to be as wide as itself.
if (colspan(elem) == 1) {
metrics.columnWidths[col] = Math.max(metrics.columnWidths[col], psize.width());
}
}
ii += colspan(elem);
}
// determine the total width needed by the fixed columns, then compute the hint given to
// free columns based on the remaining space
float fixedWidth = _colgap*(columns-1); // start with gaps, add fixed col widths
for (int cc = 0; cc < columns; cc++) fixedWidth += metrics.columnWidths[cc];
float freeHintX = (hintX - fixedWidth) / freeWeight();
ii = 0;
for (Element<?> elem : elems) {
int col = ii % columns, row = ii / columns;
if (elem.isVisible() && _columns[col]._weight > 0) {
// TODO: supply sane y hint?
IDimension psize = preferredSize(elem, freeHintX, hintY);
metrics.rowHeights[row] = Math.max(metrics.rowHeights[row], psize.height());
metrics.columnWidths[col] = Math.max(metrics.columnWidths[col], psize.width());
}
ii += colspan(elem);
}
return metrics;