From 3304d10da5f6e2e8452693d4b8262d7564d7d5e2 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Mon, 7 Mar 2022 20:21:24 +0100 Subject: [PATCH] added ListElement --- src/lib/ui/reactive/ListElement.hx | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/lib/ui/reactive/ListElement.hx 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; + } +}