From a08685b9a4235db2d53f7f7e06ca3f9b8fb43d20 Mon Sep 17 00:00:00 2001 From: FrHun <28605587+frhun@users.noreply.github.com> Date: Tue, 14 Sep 2021 20:34:04 +0200 Subject: [PATCH] LibGUI: Add utility functions to Margins --- Userland/Libraries/LibGUI/Margins.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Userland/Libraries/LibGUI/Margins.h b/Userland/Libraries/LibGUI/Margins.h index 1c0b55f2fd..71232a0bec 100644 --- a/Userland/Libraries/LibGUI/Margins.h +++ b/Userland/Libraries/LibGUI/Margins.h @@ -6,6 +6,8 @@ #pragma once +#include + namespace GUI { class Margins { @@ -41,6 +43,16 @@ public: } ~Margins() = default; + [[nodiscard]] Gfx::IntRect applied_to(Gfx::IntRect const& input) const + { + Gfx::IntRect output = input; + output.take_from_left(left()); + output.take_from_top(top()); + output.take_from_right(right()); + output.take_from_bottom(bottom()); + return output; + } + bool is_null() const { return !m_left && !m_top && !m_right && !m_bottom; } int top() const { return m_top; } @@ -61,6 +73,11 @@ public: && m_bottom == other.m_bottom; } + Margins operator+(Margins const& other) const + { + return Margins { top() + other.top(), right() + other.right(), bottom() + other.bottom(), left() + other.left() }; + } + private: int m_top { 0 }; int m_right { 0 };