Skip to content

Commit 9b50a5b

Browse files
committed
Improve table column bound calculation to take rowspans into account
1 parent aec5e5e commit 9b50a5b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/src/layout_element.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,20 @@ class TableLayoutElement extends LayoutElement {
8787
}
8888

8989
// All table rows have a height intrinsic to their (spanned) contents
90-
final rowSizes =
91-
List.generate(rows.length, (_) => IntrinsicContentTrackSize());
90+
final rowSizes = List.generate(rows.length, (_) => IntrinsicContentTrackSize());
9291

9392
// Calculate column bounds
94-
int columnMax = rows
95-
.map((row) => row.children
96-
.whereType<TableCellElement>()
97-
.fold(0, (int value, child) => value + child.colspan))
98-
.fold(0, max);
93+
int columnMax = 0;
94+
List<int> rowSpanOffsets = [];
95+
for (final row in rows) {
96+
final cols = row.children.whereType<TableCellElement>().fold(0, (int value, child) => value + child.colspan) +
97+
rowSpanOffsets.fold<int>(0, (int offset, child) => child);
98+
columnMax = max(cols, columnMax);
99+
rowSpanOffsets = [
100+
...rowSpanOffsets.map((value) => value - 1).where((value) => value > 0),
101+
...row.children.whereType<TableCellElement>().map((cell) => cell.rowspan - 1),
102+
];
103+
}
99104

100105
// Place the cells in the rows/columns
101106
final cells = <GridPlacement>[];

0 commit comments

Comments
 (0)