mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 08:31:01 +00:00
Fix text align to right/center issue
Calculate text-width in fixedWidth mode
This commit is contained in:
parent
97b60efa21
commit
d1b31649ec
1 changed files with 9 additions and 2 deletions
|
@ -1118,13 +1118,20 @@ var Text = new Class({
|
||||||
|
|
||||||
var padding = this.padding;
|
var padding = this.padding;
|
||||||
|
|
||||||
|
var textWidth;
|
||||||
|
|
||||||
if (style.fixedWidth === 0)
|
if (style.fixedWidth === 0)
|
||||||
{
|
{
|
||||||
this.width = textSize.width + padding.left + padding.right;
|
this.width = textSize.width + padding.left + padding.right;
|
||||||
|
textWidth = textSize.width;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.width = style.fixedWidth;
|
this.width = style.fixedWidth;
|
||||||
|
textWidth = this.width - padding.left - padding.right;
|
||||||
|
if (textWidth < textSize.width) {
|
||||||
|
textWidth = textSize.width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style.fixedHeight === 0)
|
if (style.fixedHeight === 0)
|
||||||
|
@ -1198,11 +1205,11 @@ var Text = new Class({
|
||||||
}
|
}
|
||||||
else if (style.align === 'right')
|
else if (style.align === 'right')
|
||||||
{
|
{
|
||||||
linePositionX += textSize.width - textSize.lineWidths[i];
|
linePositionX += textWidth - textSize.lineWidths[i];
|
||||||
}
|
}
|
||||||
else if (style.align === 'center')
|
else if (style.align === 'center')
|
||||||
{
|
{
|
||||||
linePositionX += (textSize.width - textSize.lineWidths[i]) / 2;
|
linePositionX += (textWidth - textSize.lineWidths[i]) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.autoRound)
|
if (this.autoRound)
|
||||||
|
|
Loading…
Reference in a new issue