1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-29 03:23:37 +02:00

finally center it

This commit is contained in:
Ellpeck 2019-08-15 16:29:41 +02:00
parent 481074bcc3
commit b42ec52017
3 changed files with 8 additions and 10 deletions

View file

@ -12,11 +12,11 @@ namespace MLEM.Extended.Extensions {
builder.Append(word).Append(' ');
if (font.MeasureString(builder).Width * scale >= width) {
var len = builder.Length - word.Length - 1;
yield return builder.ToString(0, len);
yield return builder.ToString(0, len - 1);
builder.Remove(0, len);
}
}
yield return builder.ToString();
yield return builder.ToString(0, builder.Length - 1);
}
}

View file

@ -44,16 +44,14 @@ namespace MLEM.Ui.Elements {
this.lineHeight = 0;
this.longestLineLength = 0;
var height = 0F;
foreach (var strg in this.splitText) {
var strgScale = this.font.MeasureString(strg) * this.TextScale * this.Scale;
height += strgScale.Y + 1;
if (strgScale.Y > this.lineHeight)
this.lineHeight = strgScale.Y;
if (strgScale.Y + 1 > this.lineHeight)
this.lineHeight = strgScale.Y + 1;
if (strgScale.X > this.longestLineLength)
this.longestLineLength = strgScale.X;
}
return new Point(this.AutoAdjustWidth ? (this.longestLineLength + this.ScaledPadding.X * 2).Ceil() : size.X, height.Ceil() + this.ScaledPadding.Y * 2);
return new Point(this.AutoAdjustWidth ? this.longestLineLength.Ceil() + this.ScaledPadding.X * 2 : size.X, (this.lineHeight * this.splitText.Length).Ceil() + this.ScaledPadding.Y * 2);
}
public override void Draw(GameTime time, SpriteBatch batch, float alpha, Point offset) {
@ -68,7 +66,7 @@ namespace MLEM.Ui.Elements {
} else {
this.font.DrawString(batch, line, pos + off, this.TextColor * alpha, 0, Vector2.Zero, this.TextScale * this.Scale, SpriteEffects.None, 0);
}
off.Y += this.lineHeight + 1;
off.Y += this.lineHeight;
}
base.Draw(time, batch, alpha, offset);
}

View file

@ -11,11 +11,11 @@ namespace MLEM.Extensions {
builder.Append(word).Append(' ');
if (font.MeasureString(builder).X * scale >= width) {
var len = builder.Length - word.Length - 1;
yield return builder.ToString(0, len);
yield return builder.ToString(0, len - 1);
builder.Remove(0, len);
}
}
yield return builder.ToString();
yield return builder.ToString(0, builder.Length - 1);
}
}