handle negative width properly

This commit is contained in:
Christopher Chedeau
2014-04-22 17:19:21 -07:00
parent aad9fab75f
commit 01ccc098c9
2 changed files with 16 additions and 3 deletions

View File

@@ -128,7 +128,7 @@ var computeLayout = (function() {
} }
function isDimDefined(node, axis) { function isDimDefined(node, axis) {
return !isUndefined(node.style[dim[axis]]); return !isUndefined(node.style[dim[axis]]) && node.style[dim[axis]] >= 0;
} }
function isPosDefined(node, pos) { function isPosDefined(node, pos) {

View File

@@ -722,6 +722,19 @@ describe('Layout', function() {
); );
}); });
it('should layout node with negative width', function() {
testLayout(
{style: {width: -31}, children: [
{style: {borderRightWidth: 5}}
]},
{width: 5, height: 0, top: 0, left: 0, children: [
{width: 5, height: 0, top: 0, left: 0}
]}
);
});
it('should layout randomly', function() { it('should layout randomly', function() {
@@ -765,8 +778,8 @@ describe('Layout', function() {
} }
function generateRandomNode() { function generateRandomNode() {
var node = {style: {}}; var node = {style: {}};
randMinMax(node, 0.5, 'width', 0, 1000); randMinMax(node, 0.5, 'width', -100, 1000);
randMinMax(node, 0.5, 'height', 0, 1000); randMinMax(node, 0.5, 'height', -100, 1000);
randMinMax(node, 0.5, 'top', -10, 10); randMinMax(node, 0.5, 'top', -10, 10);
randMinMax(node, 0.5, 'left', -10, 10); randMinMax(node, 0.5, 'left', -10, 10);
randMinMax(node, 0.5, 'right', -10, 10); randMinMax(node, 0.5, 'right', -10, 10);