renderColoredContent function
Implementation
String renderColoredContent(String content, Color color) {
if (content.isEmpty) return '';
final bgColor = colorToUvColor(color);
if (bgColor == null) return content;
final w = Layout.getWidth(content);
final h = Layout.getHeight(content);
if (w == 0 || h == 0) return content;
final canvas = Canvas(w, h);
final bgStyle = UvStyle(bg: bgColor);
// Fill background.
final bgCell = Cell(content: ' ', width: 1, style: bgStyle);
for (var y = 0; y < h; y++) {
for (var x = 0; x < w; x++) {
canvas.setCell(x, y, bgCell.clone());
}
}
// Draw content on top.
drawStyledContent(
canvas,
content,
0,
0,
bgStyle,
contentWidth: w,
contentHeight: h,
);
return canvas.render();
}