Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions packages/two_dimensional_scrollables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

* Fixes bug where having one reversed axis caused incorrect painting of a pinned row.
* Adds support for BorderRadius in TableSpanDecorations.

## 0.0.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,19 @@ class TableSpanDecoration {
const TableSpanDecoration({
this.border,
this.color,
this.borderRadius,
this.consumeSpanPadding = true,
});

/// The border drawn around the span.
final TableSpanBorder? border;

/// The radius by which the leading and trailing ends of a row or
/// column will be rounded.
///
/// Applies to the [border] and [color] of the given [TableSpan].
final BorderRadius? borderRadius;
Copy link
Member

Choose a reason for hiding this comment

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

For my own understanding: Why is this a property on TableSpanDecoration instead of on TableSpanBorder? Just going by the name, it seems to be a border property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it applies to both the color and the border. I modeled this to follow BoxDecoration, which is the same.

Copy link
Member

Choose a reason for hiding this comment

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

👍


/// The color to fill the bounds of the span with.
final Color? color;

Expand Down Expand Up @@ -364,15 +371,20 @@ class TableSpanDecoration {
/// cells.
void paint(TableSpanDecorationPaintDetails details) {
if (color != null) {
details.canvas.drawRect(
details.rect,
Paint()
..color = color!
..isAntiAlias = false,
);
final Paint paint = Paint()
..color = color!
..isAntiAlias = borderRadius != null;
if (borderRadius == null || borderRadius == BorderRadius.zero) {
details.canvas.drawRect(details.rect, paint);
} else {
details.canvas.drawRRect(
borderRadius!.toRRect(details.rect),
paint,
);
}
}
if (border != null) {
border!.paint(details);
border!.paint(details, borderRadius);
}
}
}
Expand Down Expand Up @@ -416,24 +428,33 @@ class TableSpanBorder {
/// cell representing the pinned column and separately with another
/// [TableSpanDecorationPaintDetails.rect] containing all the other unpinned
/// cells.
void paint(TableSpanDecorationPaintDetails details) {
void paint(
TableSpanDecorationPaintDetails details,
BorderRadius? borderRadius,
) {
final AxisDirection axisDirection = details.axisDirection;
switch (axisDirectionToAxis(axisDirection)) {
case Axis.horizontal:
paintBorder(
details.canvas,
details.rect,
final Border border = Border(
top: axisDirection == AxisDirection.right ? leading : trailing,
bottom: axisDirection == AxisDirection.right ? trailing : leading,
);
break;
case Axis.vertical:
paintBorder(
border.paint(
details.canvas,
details.rect,
borderRadius: borderRadius,
);
break;
case Axis.vertical:
final Border border = Border(
left: axisDirection == AxisDirection.down ? leading : trailing,
right: axisDirection == AxisDirection.down ? trailing : leading,
);
border.paint(
details.canvas,
details.rect,
borderRadius: borderRadius,
);
break;
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,21 @@ void main() {
rect: rect,
axisDirection: AxisDirection.down,
);
final BorderRadius radius = BorderRadius.circular(10.0);
decoration.paint(details);
expect(canvas.rect, rect);
expect(canvas.paint.color, const Color(0xffff0000));
expect(canvas.paint.isAntiAlias, isFalse);
final TestTableSpanBorder border = TestTableSpanBorder(
leading: const BorderSide(),
);
decoration = TableSpanDecoration(border: border);
decoration = TableSpanDecoration(
border: border,
borderRadius: radius,
);
decoration.paint(details);
expect(border.details, details);
expect(border.radius, radius);
});
}

Expand All @@ -194,8 +199,10 @@ class TestCanvas implements Canvas {
class TestTableSpanBorder extends TableSpanBorder {
TestTableSpanBorder({super.leading});
TableSpanDecorationPaintDetails? details;
BorderRadius? radius;
@override
void paint(TableSpanDecorationPaintDetails details) {
void paint(TableSpanDecorationPaintDetails details, BorderRadius? radius) {
this.details = details;
this.radius = radius;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1256,17 +1256,18 @@ void main() {
// TODO(Piinks): Rewrite this to remove golden files from this repo when
// mock_canvas is public - https://github.com/flutter/flutter/pull/131631
// * foreground, background, and precedence per mainAxis
// * Break out a separate test for padding decorations to validate paint
// rect calls
// * Break out a separate test for padding and radius decorations to
// validate paint rect calls
TableView tableView = TableView.builder(
rowCount: 2,
columnCount: 2,
columnBuilder: (int index) => TableSpan(
extent: const FixedTableSpanExtent(200.0),
padding: index == 0 ? const TableSpanPadding(trailing: 10) : null,
foregroundDecoration: const TableSpanDecoration(
foregroundDecoration: TableSpanDecoration(
consumeSpanPadding: false,
border: TableSpanBorder(
borderRadius: BorderRadius.circular(10.0),
border: const TableSpanBorder(
trailing: BorderSide(
color: Colors.orange,
width: 3,
Expand All @@ -1276,14 +1277,16 @@ void main() {
backgroundDecoration: TableSpanDecoration(
// consumePadding true by default
color: index.isEven ? Colors.red : null,
borderRadius: BorderRadius.circular(30.0),
),
),
rowBuilder: (int index) => TableSpan(
extent: const FixedTableSpanExtent(200.0),
padding: index == 1 ? const TableSpanPadding(leading: 10) : null,
foregroundDecoration: const TableSpanDecoration(
foregroundDecoration: TableSpanDecoration(
// consumePadding true by default
border: TableSpanBorder(
borderRadius: BorderRadius.circular(30.0),
border: const TableSpanBorder(
leading: BorderSide(
color: Colors.green,
width: 3,
Expand All @@ -1292,6 +1295,7 @@ void main() {
),
backgroundDecoration: TableSpanDecoration(
color: index.isOdd ? Colors.blue : null,
borderRadius: BorderRadius.circular(30.0),
consumeSpanPadding: false,
),
),
Expand Down