Add CUIRect::Margin with vec2 argument

To more conveniently create different margins in horizontal and vertical directions at the same time.
This commit is contained in:
Robert Müller 2023-10-01 11:47:42 +02:00
parent 62b9338ba4
commit 706f021f68
2 changed files with 21 additions and 17 deletions

View file

@ -136,34 +136,29 @@ void CUIRect::VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const
}
}
void CUIRect::Margin(float Cut, CUIRect *pOtherRect) const
void CUIRect::Margin(vec2 Cut, CUIRect *pOtherRect) const
{
CUIRect r = *this;
pOtherRect->x = r.x + Cut;
pOtherRect->y = r.y + Cut;
pOtherRect->w = r.w - 2 * Cut;
pOtherRect->h = r.h - 2 * Cut;
pOtherRect->x = r.x + Cut.x;
pOtherRect->y = r.y + Cut.y;
pOtherRect->w = r.w - 2 * Cut.x;
pOtherRect->h = r.h - 2 * Cut.y;
}
void CUIRect::Margin(float Cut, CUIRect *pOtherRect) const
{
Margin(vec2(Cut, Cut), pOtherRect);
}
void CUIRect::VMargin(float Cut, CUIRect *pOtherRect) const
{
CUIRect r = *this;
pOtherRect->x = r.x + Cut;
pOtherRect->y = r.y;
pOtherRect->w = r.w - 2 * Cut;
pOtherRect->h = r.h;
Margin(vec2(Cut, 0.0f), pOtherRect);
}
void CUIRect::HMargin(float Cut, CUIRect *pOtherRect) const
{
CUIRect r = *this;
pOtherRect->x = r.x;
pOtherRect->y = r.y + Cut;
pOtherRect->w = r.w;
pOtherRect->h = r.h - 2 * Cut;
Margin(vec2(0.0f, Cut), pOtherRect);
}
bool CUIRect::Inside(float PointX, float PointY) const

View file

@ -81,6 +81,15 @@ public:
*/
void VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const;
/**
* Places pOtherRect inside *this* CUIRect with Cut as the margin.
*
* @param Cut The margin as a vec2.
* The x component applies to the vertical axis.
* The y component applies to the horizontal axis.
* @param pOtherRect The CUIRect to place inside *this* CUIRect.
*/
void Margin(vec2 Cut, CUIRect *pOtherRect) const;
/**
* Places pOtherRect inside *this* CUIRect with Cut as the margin.
*