package lib.ui.elements; import lib.ui.elements.UIElement; class TextElement implements UIElement { public var text:String; private final uiEvents:UIEvents; private final style:Style; public function new(text:String, ?props: {?style:Style, ?uiEvents:UIEvents}) { this.text = text; this.uiEvents = props?.uiEvents; this.style = props?.style ?? {fgColor: White, bgColor: Black}; } public function set(text:String) { this.text = text; } public function get():String { return this.text; } public function getEventHandlers():UIEvents { return uiEvents; } public function render(bounds: Pos):Canvas { var canvas = new Canvas(); 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}); } return canvas; } }