newline support for TextElement

This commit is contained in:
Niklas Kapelle 2023-11-16 02:29:41 +01:00
parent 7f8c0d154c
commit 9bb6b8bf2b
Signed by: niklas
GPG Key ID: 4EB651B36D841D16

View File

@ -28,9 +28,19 @@ class TextElement implements UIElement {
public function render(bounds:Pos):Canvas { public function render(bounds:Pos):Canvas {
var canvas = new Canvas(); var canvas = new Canvas();
var x = 0;
var y = 0;
for (i in 0...this.text.length) { for (i in 0...this.text.length) {
var c = this.text.charAt(i); var c = this.text.charAt(i);
canvas.set({x: i, y: 0}, {bg: style.bgColor ?? Black, textColor: style.fgColor ?? White, char: c}); if (c == "\n") {
x = 0;
y++;
} else {
canvas.set({x: x, y: y}, {bg: style.bgColor ?? Black, textColor: style.fgColor ?? White, char: c});
x++;
}
} }
return canvas; return canvas;