LibGUI: Add utility functions to Margins
This commit is contained in:
parent
5275788f1e
commit
a08685b9a4
Notes:
sideshowbarker
2024-07-18 01:31:56 +09:00
Author: https://github.com/frhun Commit: https://github.com/SerenityOS/serenity/commit/a08685b9a42 Pull-request: https://github.com/SerenityOS/serenity/pull/10246 Issue: https://github.com/SerenityOS/serenity/issues/5887 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
1 changed files with 17 additions and 0 deletions
|
@ -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 };
|
||||
|
|
Loading…
Add table
Reference in a new issue