nested children

This commit is contained in:
Christopher Chedeau
2014-03-30 19:33:24 -07:00
parent 8713562160
commit cce3a4d830
3 changed files with 54 additions and 26 deletions

View File

@@ -1,28 +1,30 @@
function computeLayout(node) {
var top = 0;
var children = [];
(node.children || []).forEach(function(child) {
console.log(child);
children.push({
top: top,
left: 0,
width: child.style.width,
height: child.style.height
function layoutNode(node, parent) {
var top = 0;
var children = [];
(node.children || []).forEach(function(child) {
children.push(layoutNode(child, {
top: top,
left: 0
}));
top += child.style.height;
});
top += child.style.height;
});
var result = {
top: 0,
left: 0,
width: node.style.width,
height: node.style.height
};
var result = {
width: node.style.width,
height: node.style.height,
top: parent.top + 0,
left: parent.left + 0
};
if (children.length > 0) {
result.children = children;
if (children.length > 0) {
result.children = children;
}
return result;
}
return result;
return layoutNode(node, {top: 0, left: 0});
}