added ListElement

This commit is contained in:
Djeeberjr 2022-03-07 20:21:24 +01:00
parent 7c4fc95584
commit 3304d10da5

View File

@ -0,0 +1,42 @@
package lib.ui.reactive;
import util.ObservableArray;
import util.Vec.Vec2;
class ListElement extends UIElement {
private final content:ObservableArray<UIElement>;
public function new(content: ObservableArray<UIElement>) {
super();
this.content = content;
this.content.subscribe(value -> {
this.changedTrigger.trigger(null);
// TODO: subscribe to elements and forward onChange event
});
}
public function render(bounds:Vec2<Int>):Canvas {
var canvas: Canvas = new Canvas();
var writePoint:Vec2<Int> = {x: 0, y: 0};
for(element in this.content.get()){
if (bounds.y - writePoint.y <= 0) {
// No more space to render children
break;
}
var childRender = element.render({
x: bounds.x,
y: bounds.y - writePoint.y
});
canvas.combine(childRender, writePoint);
writePoint = {x: 0, y: writePoint.y + childRender.hight()};
}
return canvas;
}
}