some ui stuff

This commit is contained in:
2023-07-08 14:01:38 +02:00
parent 4f881117cf
commit c390519393
10 changed files with 26 additions and 435 deletions

View File

@@ -3,6 +3,7 @@ package lib.ui.elements;
class RootElement implements UIElement {
private var children:Array<UIElement>;
private final eventManager:UIEventManager = new UIEventManager();
private var title:String = "";
public function new(?children:Array<UIElement>) {
if (children == null) {
@@ -20,14 +21,21 @@ class RootElement implements UIElement {
this.children = children;
}
public function render():Canvas {
public function render(bounds: Pos):Canvas {
var canvas = new Canvas();
var offset = new Pos({x: 0, y: 0});
if (hasTitle()) {
var title = new TextElement(this.title);
var halfWidth = Math.floor(bounds.x / 2) - Math.floor(this.title.length / 2);
canvas.combine(title.render(bounds), {x: halfWidth, y: offset.y});
offset = new Pos({x: 0, y: 1});
}
this.eventManager.clearMap();
for (child in children) {
var childCanvas = child.render();
var childCanvas = child.render(bounds);
var bounds = childCanvas.getBounds();
bounds.offset(offset);
@@ -39,4 +47,12 @@ class RootElement implements UIElement {
return canvas;
}
public function setTitle(title: String) {
this.title = title;
}
private inline function hasTitle(): Bool {
return title != "";
}
}

View File

@@ -24,7 +24,7 @@ class TextElement implements UIElement {
return uiEvents;
}
public function render():Canvas {
public function render(bounds: Pos):Canvas {
var canvas = new Canvas();
for (i in 0...this.text.length) {
var c = this.text.charAt(i);

View File

@@ -3,5 +3,5 @@ package lib.ui.elements;
import lib.ui.rendere.UIEventDelegate;
interface UIElement extends UIEventDelegate {
public function render():Canvas;
public function render(bounds: Pos):Canvas;
}