flex recursively

This commit is contained in:
Christopher Chedeau
2014-04-06 09:43:16 -07:00
parent 93b47ef33a
commit 6859575797
2 changed files with 29 additions and 2 deletions

View File

@@ -223,5 +223,31 @@ describe('Layout', function() {
]
});
});
it('should layout node with flex recursively', function() {
testLayout({
style: {width: 1000, height: 1000},
children: [{
style: {width: 1000, flex: 1},
children: [{
style: {width: 1000, flex: 1},
children: [{
style: {width: 1000, flex: 1}
}]
}]
}]
}, {
width: 1000, height: 1000, top: 0, left: 0,
children: [{
width: 1000, height: 1000, top: 0, left: 0,
children: [{
width: 1000, height: 1000, top: 0, left: 0,
children: [{
width: 1000, height: 1000, top: 0, left: 0
}]
}]
}]
});
});
});

View File

@@ -60,9 +60,10 @@ function computeLayout(node) {
var flexibleMainDim =
(node.layout[dim[mainAxis]] - mainContentDim) / flexibleChildren.length;
// optim: don't allocate a new array, re-traverse + filter the initial one
flexibleChildren.forEach(function(child) {
layoutNode(child);
child.layout[dim[mainAxis]] = flexibleMainDim;
layoutNode(child);
});
var mainPos = 0;
@@ -72,7 +73,7 @@ function computeLayout(node) {
mainPos += child.layout[dim[mainAxis]] + 2 * getMargin(child);
});
if (!mainDimInStyle) {
if (node.layout[dim[mainAxis]] === undefined && !mainDimInStyle) {
node.layout[dim[mainAxis]] = mainPos;
}
node.layout[dim[crossAxis]] = node.style[dim[crossAxis]];