Implementation
static void paint(
Canvas c, String message, Map<int, Digit> digits, Color lcdForeground,
{required bool rightJustify}) {
_paint.color = lcdForeground;
final Iterable<Digit> values = message.codeUnits.map(((ch) {
final d = digits[ch];
assert(d != null,
'No LCD character for ${String.fromCharCode(ch)} in $message');
return d!;
}));
int width =
values.fold(0, (int count, Digit d) => d.noWidth ? count : count + 1);
if (rightJustify && width <= 11) {
// Go one to the left of the first digit
c.translate(_s.width * (10 - width), 0);
} else {
c.translate(0, Segments.h / 2);
final double sf = 11.0 / max(width, 11);
c.scale(sf);
c.translate(-_s.width, -Segments.h / 2);
}
for (final Digit d in values) {
if (!d.noWidth) {
c.translate(_s.width, 0);
}
for (final Path p in d.segments) {
c.drawPath(p, _paint);
}
}
}