diff --git a/RecrownedAthenaeum/UI/Modular/Modules/Text.cs b/RecrownedAthenaeum/UI/Modular/Modules/Text.cs index dfbaed8..edf3cda 100644 --- a/RecrownedAthenaeum/UI/Modular/Modules/Text.cs +++ b/RecrownedAthenaeum/UI/Modular/Modules/Text.cs @@ -18,6 +18,12 @@ namespace RecrownedAthenaeum.UI.Modular.Modules private string originalText; private string displayedText; private Vector2 modifiedTextSize; + + /// + /// Centers the text int bounds. + /// + public bool center; + /// /// Whether or not to try and wrap text automatically. Meaning will check and attempt to wrap every update. /// @@ -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 } } - /// - /// Centers this text in the given rectangle if possible. - /// - /// - /// True if succeeded and false if there isn't enough space. - 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 { diff --git a/RecrownedAthenaeum/UI/Modular/UIModule.cs b/RecrownedAthenaeum/UI/Modular/UIModule.cs index b7f9ab7..f20dbde 100644 --- a/RecrownedAthenaeum/UI/Modular/UIModule.cs +++ b/RecrownedAthenaeum/UI/Modular/UIModule.cs @@ -33,7 +33,7 @@ namespace RecrownedAthenaeum.UI.Modular /// Origin of this module. /// public Vector2 origin; - + /// /// The parent of this module. May be null. /// @@ -79,7 +79,8 @@ namespace RecrownedAthenaeum.UI.Modular int tX = rectangle.X + parentHitbox.X; int tY = rectangle.Y + parentHitbox.Y; return new Rectangle(tX, tY, rectangle.Width, rectangle.Height); - } else + } + else { return rectangle; } @@ -122,5 +123,35 @@ namespace RecrownedAthenaeum.UI.Modular origin.X = bounds.Width / 2f; origin.Y = bounds.Height / 2f; } + + /// + /// Centers this module's origin on the horizontal axis relative to the given rectangle. + /// + /// The rectangle to center it in. + /// True if possible and false if not. + public bool CenterHorizontally(Rectangle rectangle) + { + if (rectangle.Width >= bounds.Width) + { + bounds.X = rectangle.Width / 2 + rectangle.X; + return true; + } + return false; + } + + /// + /// Center's this module's origin on the vertical axis relative to the given rectangle. + /// + /// The rectangle to center in. + /// True if possible. + public bool CenterVertically(Rectangle rectangle) + { + if (rectangle.Height >= bounds.Height) + { + bounds.Y = rectangle.Height / 2 + rectangle.Y; + return true; + } + return false; + } } }