drawBorderPath static method
void
drawBorderPath(
- Canvas canvas,
- Rect rect,
- Paint borderPaint,
- Path path,
- DynamicBorderSide border,
draw the border with a optional begin, end, and offset
Implementation
static void drawBorderPath(Canvas canvas, Rect rect, Paint borderPaint,
Path path, DynamicBorderSide border) {
if (border.begin != null || border.end != null) {
PathMetric metric = path.computeMetrics().first;
double beginPX = border.begin?.toPX(constraint: metric.length) ?? 0.0;
double endPX =
border.end?.toPX(constraint: metric.length) ?? metric.length;
double shiftPX = border.shift?.toPX(constraint: metric.length) ?? 0.0;
double temp = beginPX;
beginPX = beginPX > endPX ? endPX : beginPX;
endPX = beginPX == endPX ? temp : endPX;
beginPX = beginPX.clamp(0, metric.length);
endPX = endPX.clamp(0, metric.length);
shiftPX = shiftPX.clamp(0, metric.length);
path = extractPartialPath(
metric,
beginPX + shiftPX,
endPX + shiftPX,
);
if (beginPX + shiftPX < metric.length) {
canvas.drawPath(path, borderPaint);
if (endPX + shiftPX > metric.length) {
path = extractPartialPath(
metric,
0.0,
endPX + shiftPX - metric.length,
);
canvas.drawPath(path, borderPaint);
}
} else {
path = extractPartialPath(
metric,
beginPX + shiftPX - metric.length,
endPX + shiftPX - metric.length,
);
canvas.drawPath(path, borderPaint);
}
} else {
canvas.drawPath(path, borderPaint);
}
}