Skip to content

Commit

Permalink
[two_dimensional_scrollables] Fix TableSpanDecoration rects when axes…
Browse files Browse the repository at this point in the history
… are reversed (#5916)

Fixes flutter/flutter#141704

This fixes the rect computation for TableSpanDecorations when one or both axes are reversed.
We previously fixed similar issues when the clipRects applied to areas of the table did not account for reversed. This is another similar case.
- #5187
- #5038

![image](https://github.com/flutter/packages/assets/16964204/ae7c6872-c740-4617-95a4-8302a3085d59)
  • Loading branch information
Piinks authored Jan 22, 2024
1 parent 88b7d16 commit 841fe90
Show file tree
Hide file tree
Showing 4 changed files with 697 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/two_dimensional_scrollables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.6

* Fixes an error in TableSpanDecoration when one or both axes are reversed.

## 0.0.5+2

* Fixes must_call_super lint warning from pending framework change.
Expand Down
29 changes: 23 additions & 6 deletions packages/two_dimensional_scrollables/lib/src/table_view/table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -861,31 +861,41 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
)!;

Rect getColumnRect(bool consumePadding) {
final ({double leading, double trailing}) offsetCorrection =
axisDirectionIsReversed(verticalAxisDirection)
? (
leading: leadingCell.size.height,
trailing: trailingCell.size.height,
)
: (leading: 0.0, trailing: 0.0);

return Rect.fromPoints(
parentDataOf(leadingCell).paintOffset! +
offset -
Offset(
consumePadding ? columnSpan.padding.leading : 0.0,
rowSpan.padding.leading,
rowSpan.padding.leading - offsetCorrection.leading,
),
parentDataOf(trailingCell).paintOffset! +
offset +
Offset(trailingCell.size.width, trailingCell.size.height) +
Offset(
consumePadding ? columnSpan.padding.trailing : 0.0,
rowSpan.padding.trailing,
rowSpan.padding.trailing - offsetCorrection.trailing,
),
);
}

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 All @@ -910,18 +920,25 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
)!;

Rect getRowRect(bool consumePadding) {
final ({double leading, double trailing}) offsetCorrection =
axisDirectionIsReversed(horizontalAxisDirection)
? (
leading: leadingCell.size.width,
trailing: trailingCell.size.width,
)
: (leading: 0.0, trailing: 0.0);
return Rect.fromPoints(
parentDataOf(leadingCell).paintOffset! +
offset -
Offset(
columnSpan.padding.leading,
columnSpan.padding.leading - offsetCorrection.leading,
consumePadding ? rowSpan.padding.leading : 0.0,
),
parentDataOf(trailingCell).paintOffset! +
offset +
Offset(trailingCell.size.width, trailingCell.size.height) +
Offset(
columnSpan.padding.leading,
columnSpan.padding.leading - offsetCorrection.trailing,
consumePadding ? rowSpan.padding.trailing : 0.0,
),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/two_dimensional_scrollables/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: two_dimensional_scrollables
description: Widgets that scroll using the two dimensional scrolling foundation.
version: 0.0.5+2
version: 0.0.6
repository: https://github.com/flutter/packages/tree/main/packages/two_dimensional_scrollables
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+two_dimensional_scrollables%22+

Expand Down
Loading

0 comments on commit 841fe90

Please sign in to comment.