libui: Add Rect::relative
This commit is contained in:
parent
37731d2a95
commit
25cbaf4f90
@ -29,6 +29,14 @@ namespace ui
|
|||||||
*/
|
*/
|
||||||
Point normalize(Point point);
|
Point normalize(Point point);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transform an absolute position to a position relative to this rectangle.
|
||||||
|
*
|
||||||
|
* @param pos The original absolute position.
|
||||||
|
* @return Point The position relative to this rectangle.
|
||||||
|
*/
|
||||||
|
Point relative(Point pos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return a copy of this rectangle with no negative values (normalized to 0).
|
* @brief Return a copy of this rectangle with no negative values (normalized to 0).
|
||||||
*
|
*
|
||||||
|
@ -17,6 +17,14 @@ namespace ui
|
|||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Point Rect::relative(Point point)
|
||||||
|
{
|
||||||
|
point = normalize(point);
|
||||||
|
point.x -= pos.x;
|
||||||
|
point.y -= pos.y;
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
Rect Rect::absolute()
|
Rect Rect::absolute()
|
||||||
{
|
{
|
||||||
return Rect { ui::Point { pos.x < 0 ? 0 : pos.x, pos.y < 0 ? 0 : pos.y }, width, height };
|
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