added styles to TextElement

This commit is contained in:
2023-07-11 13:17:33 +02:00
parent 8683eaf17a
commit dfaabea00d
4 changed files with 19 additions and 9 deletions

View File

@@ -6,10 +6,12 @@ class TextElement implements UIElement {
public var text:String;
private final uiEvents:UIEvents;
private final style:Style;
public function new(text:String, ?uiEvents:UIEvents) {
public function new(text:String, ?props: {?style:Style, ?uiEvents:UIEvents}) {
this.text = text;
this.uiEvents = uiEvents;
this.uiEvents = props?.uiEvents;
this.style = props?.style ?? {fgColor: White, bgColor: Black};
}
public function set(text:String) {
@@ -28,7 +30,7 @@ class TextElement implements UIElement {
var canvas = new Canvas();
for (i in 0...this.text.length) {
var c = this.text.charAt(i);
canvas.set({x: i, y: 0}, {bg: Black, textColor: White, char: c});
canvas.set({x: i, y: 0}, {bg: style.bgColor ?? Black, textColor: style.fgColor ?? White, char: c});
}
return canvas;