libui: Rename Rect::absolute to normalized and add a new absolute function

This commit is contained in:
apio 2023-08-04 16:03:25 +02:00
parent 7ab0c6b72b
commit 16fa55899e
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 30 additions and 2 deletions

View File

@ -37,11 +37,27 @@ namespace ui
*/
Point relative(Point pos);
/**
* @brief Transform a position relative to this rectangle to an absolute position.
*
* @param pos The original relative position.
* @return Point The absolute position.
*/
Point absolute(Point pos);
/**
* @brief Transform another rectangle relative to this one to an absolute rectangle.
*
* @param rect The original relative rectangle.
* @return Point The absolute rectangle.
*/
Rect absolute(Rect rect);
/**
* @brief Return a copy of this rectangle with no negative values (normalized to 0).
*
* @return Rect The new rectangle.
*/
Rect absolute();
Rect normalized();
};
}

View File

@ -25,7 +25,19 @@ namespace ui
return point;
}
Rect Rect::absolute()
Point Rect::absolute(Point point)
{
point.x += pos.x;
point.y += pos.y;
return point;
}
Rect Rect::absolute(Rect rect)
{
return Rect { absolute(rect.pos), rect.width, rect.height };
}
Rect Rect::normalized()
{
return Rect { ui::Point { pos.x < 0 ? 0 : pos.x, pos.y < 0 ? 0 : pos.y }, width, height };
}