From 9bb6b8bf2b6c185b9190e75c19d85281b3213b14 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Thu, 16 Nov 2023 02:29:41 +0100 Subject: [PATCH] newline support for TextElement --- src/lib/ui/elements/TextElement.hx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/ui/elements/TextElement.hx b/src/lib/ui/elements/TextElement.hx index f351268..8aafdf0 100644 --- a/src/lib/ui/elements/TextElement.hx +++ b/src/lib/ui/elements/TextElement.hx @@ -28,9 +28,19 @@ class TextElement implements UIElement { public function render(bounds:Pos):Canvas { var canvas = new Canvas(); + + var x = 0; + var y = 0; + for (i in 0...this.text.length) { 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;