Skip to content

Commit 1ccfd8d

Browse files
committed
In Actions.GridAlign if you set width to -1 it would align the items vertically, instead of horizontally. It now aligns them horizontally if width is set, or vertically if height is set. Fix phaserjs#4899
1 parent ec2f103 commit 1ccfd8d

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

src/actions/GridAlign.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ var GridAlign = function (items, options)
3030
{
3131
if (options === undefined) { options = {}; }
3232

33+
var widthSet = options.hasOwnProperty('width');
34+
var heightSet = options.hasOwnProperty('height');
35+
3336
var width = GetFastValue(options, 'width', -1);
3437
var height = GetFastValue(options, 'height', -1);
38+
3539
var cellWidth = GetFastValue(options, 'cellWidth', 1);
3640
var cellHeight = GetFastValue(options, 'cellHeight', cellWidth);
41+
3742
var position = GetFastValue(options, 'position', CONST.TOP_LEFT);
3843
var x = GetFastValue(options, 'x', 0);
3944
var y = GetFastValue(options, 'y', 0);
@@ -50,31 +55,15 @@ var GridAlign = function (items, options)
5055
{
5156
AlignIn(items[i], tempZone, position);
5257

53-
if (width === -1)
58+
if (widthSet && width === -1)
5459
{
5560
// We keep laying them out horizontally until we've done them all
56-
cy += cellHeight;
57-
tempZone.y += cellHeight;
58-
59-
if (cy === h)
60-
{
61-
cy = 0;
62-
tempZone.x += cellWidth;
63-
tempZone.y = y;
64-
}
61+
tempZone.x += cellWidth;
6562
}
66-
else if (height === -1)
63+
else if (heightSet && height === -1)
6764
{
6865
// We keep laying them out vertically until we've done them all
69-
cx += cellWidth;
70-
tempZone.x += cellWidth;
71-
72-
if (cx === w)
73-
{
74-
cx = 0;
75-
tempZone.x = x;
76-
tempZone.y += cellHeight;
77-
}
66+
tempZone.y += cellHeight;
7867
}
7968
else
8069
{

0 commit comments

Comments
 (0)