Added PainterDelegate
that can be used to customize the way the text will be drawn.
With the delegate you can control when the text will be drawn with painter.paint(canvas, size)
, so you can add a decoration before and after the text:
This layout can be achieved with the following delegate:
void delegate(Canvas canvas, Size size, ArcTextPainter painter) {
final rect = Rect.fromLTWH(0, 0, size.width, size.height);
canvas.drawArc(
rect,
painter.startAngle,
painter.sweepAngle,
false,
_decorationPaint,
);
painter.paint(canvas, size);
canvas.drawArc(
rect,
painter.finalAngle + radians(10),
2 * pi - painter.sweepAngle - radians(20),
false,
_backgroundPaint,
);
}
It introduces some breaking changes:
getFinalAngle
is changed to sweepAngle
getter, as it actually returns the total angle, not the absolute final angle.
paint
now accepts Size
instead of Offset
and offset is always in the center of this Size
rectangle. It makes delegate simpler.
There's one thing I don't like here: using drawArc
you still have to add -pi / 2
for the angles, as drawArc
0 angle is at point (1; 0)
. For me, 0
angle should start at point (0; 1)
, so it was implemented like this in the library. I'm not sure whether it makes sense to introduce another breaking change and make library's 0
angle aligned with drawArc
.