Skip to content

Commit

Permalink
HorizontalLayout, VerticalLayout: Fixed issue where scaleX and scaleY…
Browse files Browse the repository at this point in the history
… were not accounted for when using pivotX and pivotY (closes #1696)
  • Loading branch information
joshtynjala committed Mar 5, 2018
1 parent 748aa61 commit 17e33ea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
21 changes: 16 additions & 5 deletions source/feathers/layout/HorizontalLayout.as
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,12 @@ package feathers.layout
{
continue;
}
item.x = item.pivotX + positionX;
var pivotX:Number = item.pivotX;
if(pivotX !== 0)
{
pivotX *= item.scaleX;
}
item.x = pivotX + positionX;
var itemWidth:Number;
if(hasDistributedWidth)
{
Expand Down Expand Up @@ -668,12 +673,18 @@ package feathers.layout
continue;
}

var pivotY:Number = item.pivotY;
if(pivotY !== 0)
{
pivotY *= item.scaleY;
}

//in this section, we handle vertical alignment and percent
//height from HorizontalLayoutData
if(this._verticalAlign == VerticalAlign.JUSTIFY)
{
//if we justify items vertically, we can skip percent height
item.y = item.pivotY + boundsY + this._paddingTop;
item.y = pivotY + boundsY + this._paddingTop;
item.height = availableHeightMinusPadding;
}
else
Expand Down Expand Up @@ -735,17 +746,17 @@ package feathers.layout
{
case VerticalAlign.BOTTOM:
{
item.y = item.pivotY + boundsY + verticalAlignHeight - this._paddingBottom - item.height;
item.y = pivotY + boundsY + verticalAlignHeight - this._paddingBottom - item.height;
break;
}
case VerticalAlign.MIDDLE:
{
item.y = item.pivotY + boundsY + this._paddingTop + Math.round((verticalAlignHeight - this._paddingTop - this._paddingBottom - item.height) / 2);
item.y = pivotY + boundsY + this._paddingTop + Math.round((verticalAlignHeight - this._paddingTop - this._paddingBottom - item.height) / 2);
break;
}
default: //top
{
item.y = item.pivotY + boundsY + this._paddingTop;
item.y = pivotY + boundsY + this._paddingTop;
}
}
}
Expand Down
21 changes: 16 additions & 5 deletions source/feathers/layout/VerticalLayout.as
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,12 @@ package feathers.layout
{
continue;
}
item.y = item.pivotY + positionY;
var pivotY:Number = item.pivotY;
if(pivotY !== 0)
{
pivotY *= item.scaleY;
}
item.y = pivotY + positionY;
var itemWidth:Number = item.width;
var itemHeight:Number;
if(hasDistributedHeight)
Expand Down Expand Up @@ -822,12 +827,18 @@ package feathers.layout
continue;
}

var pivotX:Number = item.pivotX;
if(pivotX !== 0)
{
pivotX *= item.scaleX;
}

//in this section, we handle horizontal alignment and percent
//width from VerticalLayoutData
if(this._horizontalAlign == HorizontalAlign.JUSTIFY)
{
//if we justify items horizontally, we can skip percent width
item.x = item.pivotX + boundsX + this._paddingLeft;
item.x = pivotX + boundsX + this._paddingLeft;
item.width = availableWidthMinusPadding;
}
else
Expand Down Expand Up @@ -889,19 +900,19 @@ package feathers.layout
{
case HorizontalAlign.RIGHT:
{
item.x = item.pivotX + boundsX + horizontalAlignWidth - this._paddingRight - item.width;
item.x = pivotX + boundsX + horizontalAlignWidth - this._paddingRight - item.width;
break;
}
case HorizontalAlign.CENTER:
{
//round to the nearest pixel when dividing by 2 to
//align in the center
item.x = item.pivotX + boundsX + this._paddingLeft + Math.round((horizontalAlignWidth - this._paddingLeft - this._paddingRight - item.width) / 2);
item.x = pivotX + boundsX + this._paddingLeft + Math.round((horizontalAlignWidth - this._paddingLeft - this._paddingRight - item.width) / 2);
break;
}
default: //left
{
item.x = item.pivotX + boundsX + this._paddingLeft;
item.x = pivotX + boundsX + this._paddingLeft;
}
}
}
Expand Down

0 comments on commit 17e33ea

Please sign in to comment.