libui: Add Rect::contains(Rect)

This commit is contained in:
apio 2023-08-06 12:44:16 +02:00
parent 35d2bd6931
commit c0ada40e2c
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 18 additions and 0 deletions

View File

@ -21,6 +21,15 @@ namespace ui
*/
bool contains(Point point);
/**
* @brief Check if another rectangle is contained in this one.
*
* @param point The rectangle to check.
* @return true The other rectangle is contained inside this one.
* @return false The other rectangle is not contained inside this one.
*/
bool contains(Rect rect);
/**
* @brief Normalize a point to fit inside this rectangle.
*

View File

@ -8,6 +8,15 @@ namespace ui
(point.y <= (pos.y + height));
}
bool Rect::contains(Rect rect)
{
if (!contains(rect.pos)) return false;
Point rel = relative(rect.pos);
if ((rel.x + rect.width) > width) return false;
if ((rel.y + rect.height) > height) return false;
return true;
}
Point Rect::normalize(Point point)
{
if (point.x < pos.x) point.x = pos.x;