paint method
Paints the border around the given Rect on the given Canvas, with the given rows and columns.
Uniform borders are more efficient to paint than more complex borders.
The rows
argument specifies the vertical positions between the rows,
relative to the given rectangle. For example, if the table contained two
rows of height 100.0 each, then rows
would contain a single value,
100.0, which is the vertical position between the two rows (relative to
the top edge of rect
).
The columns
argument specifies the horizontal positions between the
columns, relative to the given rectangle. For example, if the table
contained two columns of height 100.0 each, then columns
would contain a
single value, 100.0, which is the vertical position between the two
columns (relative to the left edge of rect
).
The verticalInside border is only drawn if there are at least two columns. The horizontalInside border is only drawn if there are at least two rows. The horizontal borders are drawn after the vertical borders.
The outer borders (in the order top, right, bottom, left, with left above the others) are painted after the inner borders.
The paint order is particularly notable in the case of partially-transparent borders.
Implementation
void paint(
Canvas canvas,
Rect rect, {
required Iterable<double> rows,
required Iterable<double> columns,
}) {
// properties can't be null
// arguments can't be null
assert(rows.isEmpty || (rows.first >= 0.0 && rows.last <= rect.height));
assert(columns.isEmpty || (columns.first >= 0.0 && columns.last <= rect.width));
if (columns.isNotEmpty || rows.isNotEmpty) {
final Paint paint = Paint();
final Path path = Path();
if (columns.isNotEmpty) {
switch (verticalInside.style) {
case BorderStyle.solid:
paint
..color = verticalInside.color
..strokeWidth = verticalInside.width
..style = PaintingStyle.stroke;
path.reset();
for (final double x in columns) {
path.moveTo(rect.left + x, rect.top);
path.lineTo(rect.left + x, rect.bottom);
}
canvas.drawPath(path, paint);
case BorderStyle.none:
break;
}
}
if (rows.isNotEmpty) {
switch (horizontalInside.style) {
case BorderStyle.solid:
paint
..color = horizontalInside.color
..strokeWidth = horizontalInside.width
..style = PaintingStyle.stroke;
path.reset();
for (final double y in rows) {
path.moveTo(rect.left, rect.top + y);
path.lineTo(rect.right, rect.top + y);
}
canvas.drawPath(path, paint);
case BorderStyle.none:
break;
}
}
}
if (!isUniform || borderRadius == BorderRadius.zero) {
paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left);
} else {
final RRect outer = borderRadius.toRRect(rect);
final RRect inner = outer.deflate(top.width);
final Paint paint = Paint()..color = top.color;
canvas.drawDRRect(outer, inner, paint);
}
}