diff --git a/src/lib/ui/reactive/ListElement.hx b/src/lib/ui/reactive/ListElement.hx new file mode 100644 index 0000000..2b367e8 --- /dev/null +++ b/src/lib/ui/reactive/ListElement.hx @@ -0,0 +1,42 @@ +package lib.ui.reactive; + +import util.ObservableArray; +import util.Vec.Vec2; + +class ListElement extends UIElement { + + private final content:ObservableArray; + + public function new(content: ObservableArray) { + 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):Canvas { + var canvas: Canvas = new Canvas(); + var writePoint:Vec2 = {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; + } +}