something something ui
This commit is contained in:
42
src/lib/ui/elements/RootElement.hx
Normal file
42
src/lib/ui/elements/RootElement.hx
Normal file
@@ -0,0 +1,42 @@
|
||||
package lib.ui.elements;
|
||||
|
||||
class RootElement implements UIElement {
|
||||
private var children:Array<UIElement>;
|
||||
private final eventManager:UIEventManager = new UIEventManager();
|
||||
|
||||
public function new(?children:Array<UIElement>) {
|
||||
if (children == null) {
|
||||
children = [];
|
||||
} else {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
||||
|
||||
public function getEventHandlers():UIEvents {
|
||||
return eventManager.getEventHandlers();
|
||||
}
|
||||
|
||||
public function setChildren(children:Array<UIElement>) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public function render():Canvas {
|
||||
var canvas = new Canvas();
|
||||
var offset = new Pos({x: 0, y: 0});
|
||||
|
||||
this.eventManager.clearMap();
|
||||
|
||||
for (child in children) {
|
||||
var childCanvas = child.render();
|
||||
var bounds = childCanvas.getBounds();
|
||||
bounds.offset(offset);
|
||||
|
||||
this.eventManager.addMapElement(child, bounds);
|
||||
canvas.combine(childCanvas, offset);
|
||||
|
||||
offset = new Pos({x: 0, y: offset.y + bounds.getHight() + 1});
|
||||
}
|
||||
|
||||
return canvas;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user