some ui stuff
This commit is contained in:
@@ -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 != "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user