libui: Rename Rect::absolute to normalized and add a new absolute function
This commit is contained in:
parent
a5d33fdf44
commit
d9557e5089
@ -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();
|
||||
};
|
||||
}
|
||||
|
@ -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 };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user