LibGUI: Add utility functions to Margins

This commit is contained in:
FrHun 2021-09-14 20:34:04 +02:00 committed by Andreas Kling
parent 5275788f1e
commit a08685b9a4
Notes: sideshowbarker 2024-07-18 01:31:56 +09:00

View File

@ -6,6 +6,8 @@
#pragma once
#include <LibGfx/Rect.h>
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 };