Added UI automatic centering.
This commit is contained in:
@@ -18,6 +18,12 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
private string originalText;
|
||||
private string displayedText;
|
||||
private Vector2 modifiedTextSize;
|
||||
|
||||
/// <summary>
|
||||
/// Centers the text int bounds.
|
||||
/// </summary>
|
||||
public bool center;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to try and wrap text automatically. Meaning will check and attempt to wrap every update.
|
||||
/// </summary>
|
||||
@@ -67,6 +73,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
if (useEllipses) AttemptToApplyEllipsis();
|
||||
if (autoWrap) AttemptToWrapText();
|
||||
if (autoScale) AttemptToScaleFont();
|
||||
if (center) Center();
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
@@ -173,27 +180,22 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Centers this text in the given rectangle if possible.
|
||||
/// </summary>
|
||||
/// <param name="rectangle"></param>
|
||||
/// <returns>True if succeeded and false if there isn't enough space.</returns>
|
||||
public bool CenterIn(Rectangle rectangle)
|
||||
private bool Center()
|
||||
{
|
||||
Vector2 textSize = new Vector2(modifiedTextSize.X * scale, modifiedTextSize.Y * scale);
|
||||
|
||||
if (textSize.X <= rectangle.Width)
|
||||
if (textSize.X <= bounds.Width)
|
||||
{
|
||||
position.X = rectangle.X + (rectangle.Width - textSize.X) / 2f;
|
||||
position.X = bounds.X + (bounds.Width - textSize.X) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (textSize.Y <= rectangle.Height)
|
||||
if (textSize.Y <= bounds.Height)
|
||||
{
|
||||
position.Y = rectangle.Y + (rectangle.Height - textSize.Y) / 2f;
|
||||
position.Y = bounds.Y + (bounds.Height - textSize.Y) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user