Skip to content

Commit

Permalink
Merge pull request #138 from mattgodbolt/fix-for-non-integral-contain…
Browse files Browse the repository at this point in the history
…er-widths

Round down the additionalPixel to prevent an extra pixel creeping in
  • Loading branch information
WolframHempel committed Sep 18, 2016
2 parents b860192 + fc4cbe2 commit 2346c0c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/goldenlayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3577,7 +3577,7 @@ lm.utils.copy( lm.items.RowOrColumn.prototype, {
itemSizes.push( itemSize );
}

additionalPixel = ( this._isColumn ? totalHeight : totalWidth ) - totalAssigned;
additionalPixel = Math.floor( ( this._isColumn ? totalHeight : totalWidth ) - totalAssigned );

for( i = 0; i < this.contentItems.length; i++ ) {
if( additionalPixel - i > 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/items/RowOrColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ lm.utils.copy( lm.items.RowOrColumn.prototype, {
itemSizes.push( itemSize );
}

additionalPixel = ( this._isColumn ? totalHeight : totalWidth ) - totalAssigned;
additionalPixel = Math.floor( ( this._isColumn ? totalHeight : totalWidth ) - totalAssigned );

for( i = 0; i < this.contentItems.length; i++ ) {
if( additionalPixel - i > 0 ) {
Expand Down
46 changes: 46 additions & 0 deletions test/container-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
describe( 'things', function () {
var layout;

it( 'creates a layout', function () {
layout = testTools.createLayout( {
content: [ {
type: 'row',
content: [ {
type: 'component',
componentName: 'testComponent'
},
{
type: 'component',
componentName: 'testComponent',
} ]
} ]
} );
} );

it( 'does not overallocate space', function () {
var root = $( 'body' );
expect( layout.isInitialised ).toBe( true );
function testWidth( width ) {
root.width( width );
layout.updateSize();
var item1 = layout.root.contentItems[ 0 ].contentItems[ 0 ],
item2 = layout.root.contentItems[ 0 ].contentItems[ 1 ];
var totalWidth = item1.element.width() + item2.element.width() + layout.config.dimensions.borderWidth;

expect( totalWidth ).toBe( Math.floor( width ) );
}

testWidth( 1000 );
testWidth( 500 );
testWidth( 50 );
testWidth( 30 );
testWidth( 31 );
testWidth( 1000.5 );
testWidth( 1000.1 );
testWidth( 1000.999 );
} );

it( 'destroys the layout', function () {
layout.destroy();
} );
} );

0 comments on commit 2346c0c

Please sign in to comment.