diff --git a/Userland/Libraries/LibGfx/Rect.cpp b/Userland/Libraries/LibGfx/Rect.cpp index 1f0d39d440..0a9ce4fc3b 100644 --- a/Userland/Libraries/LibGfx/Rect.cpp +++ b/Userland/Libraries/LibGfx/Rect.cpp @@ -141,6 +141,16 @@ void Rect::align_within(const Rect& other, TextAlignment alignment) } } +template +void Rect::set_size_around(const Size& new_size, const Point& fixed_point) +{ + const T new_x = fixed_point.x() - (T)(new_size.width() * ((float)(fixed_point.x() - x()) / width())); + const T new_y = fixed_point.y() - (T)(new_size.height() * ((float)(fixed_point.y() - y()) / height())); + + set_location({ new_x, new_y }); + set_size(new_size); +} + template<> String IntRect::to_string() const { diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index e9ad4b136e..a6997a4bc6 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -114,6 +114,8 @@ public: m_size = size; } + void set_size_around(const Size&, const Point& fixed_point); + void set_size(T width, T height) { m_size.set_width(width);