nested children
This commit is contained in:
@@ -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});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user