Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Found bug, ugh
  • Loading branch information
Piinks committed Jan 23, 2024
commit bd84020a1e57b4f36910ed5797d4646fc5d7d797
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ import 'table_span.dart';
/// vertically. If there is not enough space for all the columns, it will
/// scroll horizontally.
///
/// Each child [Widget] can belong to exactly one row and one column as
/// represented by its [TableVicinity]. The table supports lazy rendering and
/// will only instantiate those cells that are currently visible in the table's
/// viewport and those that extend into the [cacheExtent].
/// Each child [TableViewCell] can belong to exactly one row and one column as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

über-nit: What do you think about inserting an "either" in this sentence between "to" and "exactly"? The first part of the sentence makes it sound like we don't support merged cells at all and then the second part catches you by surprise. With that either we can maybe emphasize a little more that the "exactly one row/column" is not the whole story.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes excellent sense to me!

/// represented by its [TableVicinity], or it can span multiple rows and columns
/// through merging. The table supports lazy rendering and will only instantiate
/// those cells that are currently visible in the table's viewport and those
/// that extend into the [cacheExtent]. Therefore, when merging cells in a
/// [TableView], the same child should be returned from every vicinity the
/// merged cell contains. The `build` method will only be called once for a
/// merged cell, but since the table's children are lazily laid out, returning
/// the same child ensures the merged cell can be built no matter which part of
/// it is visible.
///
/// The layout of the table (e.g. how many rows/columns there are and their
/// extents) as well as the content of the individual cells is defined by
Expand Down Expand Up @@ -751,6 +757,9 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {

if (cell != null) {
final TableViewParentData cellParentData = parentDataOf(cell);
if (vicinity == TableVicinity.zero) {
print(cellParentData);
}

// Merged cell handling
if (cellParentData.rowMergeStart != null ||
Expand Down Expand Up @@ -817,6 +826,12 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
mergedRowHeight! + _rowMetrics[currentRow]!.extent;
int currentColumn = columnMergeStart;
while (currentColumn <= lastColumn) {
if (vicinity == TableVicinity.zero) {
print(TableVicinity(
row: currentRow,
column: currentColumn,
));
}
_mergedColumns.add(currentColumn);
mergedColumnWidth =
mergedColumnWidth! + _columnMetrics[currentColumn]!.extent;
Expand All @@ -830,6 +845,11 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
}
}

if (vicinity == TableVicinity.zero) {
print('mergedColumnWidth $mergedColumnWidth');
print('mergedRowHeight $mergedRowHeight');
}

final BoxConstraints cellConstraints = BoxConstraints.tightFor(
width: mergedColumnWidth ?? standardColumnWidth,
height: mergedRowHeight ?? standardRowHeight,
Expand Down Expand Up @@ -1112,12 +1132,14 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
columnSpan = _columnMetrics[columnIndex]!.configuration;
if (columnSpan.backgroundDecoration != null) {
final Rect rect = getColumnRect(
columnSpan.backgroundDecoration!.consumeSpanPadding,);
columnSpan.backgroundDecoration!.consumeSpanPadding,
);
backgroundColumns[rect] = columnSpan.backgroundDecoration!;
}
if (columnSpan.foregroundDecoration != null) {
final Rect rect = getColumnRect(
columnSpan.foregroundDecoration!.consumeSpanPadding,);
columnSpan.foregroundDecoration!.consumeSpanPadding,
);
foregroundColumns[rect] = columnSpan.foregroundDecoration!;
}
}
Expand Down Expand Up @@ -1228,13 +1250,15 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
parentDataOf(leadingCell).tableVicinity.row;
rowSpan = _rowMetrics[rowIndex]!.configuration;
if (rowSpan.backgroundDecoration != null) {
final Rect rect =
getRowRect(rowSpan.backgroundDecoration!.consumeSpanPadding,);
final Rect rect = getRowRect(
rowSpan.backgroundDecoration!.consumeSpanPadding,
);
backgroundRows[rect] = rowSpan.backgroundDecoration!;
}
if (rowSpan.foregroundDecoration != null) {
final Rect rect =
getRowRect(rowSpan.foregroundDecoration!.consumeSpanPadding,);
final Rect rect = getRowRect(
rowSpan.foregroundDecoration!.consumeSpanPadding,
);
foregroundRows[rect] = rowSpan.foregroundDecoration!;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class TableVicinity extends ChildVicinity {
/// Equivalent to the [xIndex].
int get column => xIndex;

///
/// The origin vicinity of the [TableView], (0,0).
static const TableVicinity zero = TableVicinity(row: 0, column: 0);

/// Returns a new TableVicinity, copying over the row and column fields with
/// Returns a new [TableVicinity], copying over the row and column fields with
/// those provided, or maintaining the original values.
TableVicinity copyWith({
int? row,
Expand Down Expand Up @@ -98,7 +98,14 @@ class TableViewParentData extends TwoDimensionalViewportParentData {
}
}

/// Creates a cell of the [TableView], along with information regarding merged
/// cells and [RepaintBoundary]s.
///
/// When merging cells in a [TableView], the same child should be returned from
/// every vicinity the merged cell contains. The `build` method will only be
/// called once for a merged cell, but since the table's children are lazily
/// laid out, returning the same child ensures the merged cell can be built no
/// matter which part of it is visible.
class TableViewCell extends StatelessWidget {
/// Creates a widget that controls how a child of a [TableView] spans across
/// multiple rows or columns.
Expand All @@ -115,11 +122,15 @@ class TableViewCell extends StatelessWidget {
(rowMergeStart != null && rowMergeSpan != null),
'Row merge start and span must both be set, or both unset.',
),
assert(rowMergeStart == null || rowMergeStart >= 0),
assert(rowMergeSpan == null || rowMergeSpan > 0),
assert(
(columnMergeStart == null && columnMergeSpan == null) ||
(columnMergeStart != null && columnMergeSpan != null),
'Column merge start and span must both be set, or both unset.',
);
),
assert(columnMergeStart == null || columnMergeStart >= 0),
assert(columnMergeSpan == null || columnMergeSpan > 0);

/// The child contained in this cell of the [TableView].
final Widget child;
Expand Down Expand Up @@ -184,16 +195,7 @@ class _TableViewCell extends ParentDataWidget<TableViewParentData> {
this.columnMergeStart,
this.columnMergeSpan,
required super.child,
}) : assert(
(rowMergeStart == null && rowMergeSpan == null) ||
(rowMergeStart != null && rowMergeSpan != null),
'Row merge start and span must both be set, or both unset.',
),
assert(
(columnMergeStart == null && columnMergeSpan == null) ||
(columnMergeStart != null && columnMergeSpan != null),
'Column merge start and span must both be set, or both unset.',
);
});

final int? rowMergeStart;
final int? rowMergeSpan;
Expand All @@ -206,18 +208,22 @@ class _TableViewCell extends ParentDataWidget<TableViewParentData> {
renderObject.parentData! as TableViewParentData;
bool needsLayout = false;
if (parentData.rowMergeStart != rowMergeStart) {
assert(rowMergeStart == null || rowMergeStart! >= 0);
parentData.rowMergeStart = rowMergeStart;
needsLayout = true;
}
if (parentData.rowMergeSpan != rowMergeSpan) {
assert(rowMergeSpan == null || rowMergeSpan! > 0);
parentData.rowMergeSpan = rowMergeSpan;
needsLayout = true;
}
if (parentData.columnMergeStart != columnMergeStart) {
assert(columnMergeStart == null || columnMergeStart! >= 0);
parentData.columnMergeStart = columnMergeStart;
needsLayout = true;
}
if (parentData.columnMergeSpan != columnMergeSpan) {
assert(columnMergeSpan == null || columnMergeSpan! > 0);
parentData.columnMergeSpan = columnMergeSpan;
needsLayout = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ class TableCellBuilderDelegate extends TwoDimensionalChildBuilderDelegate
cellBuilder(context, vicinity as TableVicinity),
maxXIndex: columnCount - 1,
maxYIndex: rowCount - 1,
addRepaintBoundaries: false, // repaintBoundaries handled by TableViewCell
addRepaintBoundaries:
false, // repaintBoundaries handled by TableViewCell
);

@override
Expand Down Expand Up @@ -237,7 +238,8 @@ class TableCellListDelegate extends TwoDimensionalChildListDelegate
_pinnedRowCount = pinnedRowCount,
super(
children: cells,
addRepaintBoundaries: false, // repaintBoundaries handled by TableViewCell
addRepaintBoundaries:
false, // repaintBoundaries handled by TableViewCell
) {
// Even if there are merged cells, they should be represented by the same
// child in each cell location. This ensures that no matter which direction
Expand Down
Loading