Added UI automatic centering.

This commit is contained in:
2019-03-08 10:14:51 -06:00
parent ebe22fa9dc
commit 5ffdc3a9d6
2 changed files with 45 additions and 12 deletions

View File

@@ -33,7 +33,7 @@ namespace RecrownedAthenaeum.UI.Modular
/// Origin of this module.
/// </summary>
public Vector2 origin;
/// <summary>
/// The parent of this module. May be null.
/// </summary>
@@ -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;
}
/// <summary>
/// Centers this module's origin on the horizontal axis relative to the given rectangle.
/// </summary>
/// <param name="rectangle">The rectangle to center it in.</param>
/// <returns>True if possible and false if not.</returns>
public bool CenterHorizontally(Rectangle rectangle)
{
if (rectangle.Width >= bounds.Width)
{
bounds.X = rectangle.Width / 2 + rectangle.X;
return true;
}
return false;
}
/// <summary>
/// Center's this module's origin on the vertical axis relative to the given rectangle.
/// </summary>
/// <param name="rectangle">The rectangle to center in.</param>
/// <returns>True if possible.</returns>
public bool CenterVertically(Rectangle rectangle)
{
if (rectangle.Height >= bounds.Height)
{
bounds.Y = rectangle.Height / 2 + rectangle.Y;
return true;
}
return false;
}
}
}