From 28d98f54ffe42f0b10971789214e765f2fae098c Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Wed, 9 Mar 2022 19:00:53 +1100
Subject: Add divs enclosing parent-area-using tiles

---
 src/components/TileTree.vue | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

(limited to 'src/components/TileTree.vue')

diff --git a/src/components/TileTree.vue b/src/components/TileTree.vue
index 5c3d08e..a772594 100644
--- a/src/components/TileTree.vue
+++ b/src/components/TileTree.vue
@@ -27,12 +27,14 @@ export default {
 			let tree = {
 				tolNode:tol, children:[],
 				x:0, y:0, w:0, h:0, headerSz:0,
+				sideArea:{x:0, y:0, w:0, h:0, sweptLeft:false, extraSz:0},
 			};
 			function initTreeRec(tree, lvl){
 				if (lvl > 0)
 					tree.children = tree.tolNode.children.map(tNode => initTreeRec({
 						tolNode: tNode, children: [],
 						x:0, y:0, w:0, h:0, headerSz:0,
+						sideArea:{x:0, y:0, w:0, h:0, sweptLeft:false, extraSz:0},
 					}, lvl-1));
 				return tree;
 			}
@@ -78,13 +80,25 @@ export default {
 			}
 		},
 		applyLayout(layout, tree){
-			//layout format: {x, y, w, h, headerSz, children:[layout1, ...], contentW, contentH, empSpc}
+			//layout format: {x, y, w, h, headerSz, children:[layout1, ...], contentW, contentH, empSpc, sideArea}
 			tree.x = layout.x;
 			tree.y = layout.y;
 			tree.w = layout.w;
 			tree.h = layout.h;
 			tree.headerSz = layout.headerSz;
 			layout.children.forEach((n,i) => this.applyLayout(n, tree.children[i]));
+			//handle case where leaf nodes placed in leftover space from parent-sweep
+			if (layout.sideArea){
+				//add parent area coords
+				tree.sideArea = layout.sideArea;
+				//move leaf node children to parent area
+				tree.children.filter(n => n.children.length == 0).map(n => {
+					n.x += layout.sideArea.x;
+					n.y += layout.sideArea.y;
+				});
+			} else {
+				tree.sideArea = {x:0, y:0, w:0, h:0, sweptLeft:false, extraSz:0};
+			}
 		}
 	},
 	created(){
-- 
cgit v1.2.3

