mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
LibGUI: Add utility functions to Margins
This commit is contained in:
parent
5275788f1e
commit
a08685b9a4
1 changed files with 17 additions and 0 deletions
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGfx/Rect.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
class Margins {
|
class Margins {
|
||||||
|
@ -41,6 +43,16 @@ public:
|
||||||
}
|
}
|
||||||
~Margins() = default;
|
~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; }
|
bool is_null() const { return !m_left && !m_top && !m_right && !m_bottom; }
|
||||||
|
|
||||||
int top() const { return m_top; }
|
int top() const { return m_top; }
|
||||||
|
@ -61,6 +73,11 @@ public:
|
||||||
&& m_bottom == other.m_bottom;
|
&& 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:
|
private:
|
||||||
int m_top { 0 };
|
int m_top { 0 };
|
||||||
int m_right { 0 };
|
int m_right { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue