float spaceRightLast = 0;
for (int i = 0; i < cellCount; i++) {
Cell c = cells.get(i);
int column = c.column, row = c.row, colspan = c.colspan;
Actor a = c.actor;
// Collect columns/rows that expand.
if (c.expandY != 0 && expandHeight[row] == 0) expandHeight[row] = c.expandY;
if (colspan == 1 && c.expandX != 0 && expandWidth[column] == 0) expandWidth[column] = c.expandX;
// Compute combined padding/spacing for cells.
// Spacing between actors isn't additive, the larger is used. Also, no spacing around edges.
c.computedPadLeft = c.padLeft.get(a) + (column == 0 ? 0 : Math.max(0, c.spaceLeft.get(a) - spaceRightLast));
c.computedPadTop = c.padTop.get(a);
if (c.cellAboveIndex != -1) {
Cell above = cells.get(c.cellAboveIndex);
c.computedPadTop += Math.max(0, c.spaceTop.get(a) - above.spaceBottom.get(a));
}
float spaceRight = c.spaceRight.get(a);
c.computedPadRight = c.padRight.get(a) + ((column + colspan) == columns ? 0 : spaceRight);
c.computedPadBottom = c.padBottom.get(a) + (row == rows - 1 ? 0 : c.spaceBottom.get(a));
spaceRightLast = spaceRight;
// Determine minimum and preferred cell sizes.
float prefWidth = c.prefWidth.get(a);
float prefHeight = c.prefHeight.get(a);
float minWidth = c.minWidth.get(a);
float minHeight = c.minHeight.get(a);
float maxWidth = c.maxWidth.get(a);
float maxHeight = c.maxHeight.get(a);
if (prefWidth < minWidth) prefWidth = minWidth;
if (prefHeight < minHeight) prefHeight = minHeight;
if (maxWidth > 0 && prefWidth > maxWidth) prefWidth = maxWidth;
if (maxHeight > 0 && prefHeight > maxHeight) prefHeight = maxHeight;
if (colspan == 1) { // Spanned column min and pref width is added later.
float hpadding = c.computedPadLeft + c.computedPadRight;
columnPrefWidth[column] = Math.max(columnPrefWidth[column], prefWidth + hpadding);
columnMinWidth[column] = Math.max(columnMinWidth[column], minWidth + hpadding);
}
float vpadding = c.computedPadTop + c.computedPadBottom;
rowPrefHeight[row] = Math.max(rowPrefHeight[row], prefHeight + vpadding);
rowMinHeight[row] = Math.max(rowMinHeight[row], minHeight + vpadding);
}
// Colspan with expand will expand all spanned columns if none of the spanned columns have expand.
outer:
for (int i = 0; i < cellCount; i++) {
Cell c = cells.get(i);
if (c.expandX == 0) continue;
int column = c.column;
int nn = column + c.colspan;
for (int ii = column; ii < nn; ii++)
if (expandWidth[ii] != 0) continue outer;
int expandX = c.expandX;
for (int ii = column; ii < nn; ii++)
expandWidth[ii] = expandX;
}
// Distribute any additional min and pref width added by colspanned cells to the columns spanned.
for (int i = 0; i < cellCount; i++) {
Cell c = cells.get(i);
int colspan = c.colspan;
if (colspan == 1) continue;
int column = c.column;
Actor a = c.actor;
float minWidth = c.minWidth.get(a);
float prefWidth = c.prefWidth.get(a);
float maxWidth = c.maxWidth.get(a);
if (prefWidth < minWidth) prefWidth = minWidth;
if (maxWidth > 0 && prefWidth > maxWidth) prefWidth = maxWidth;