1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:17:45 +00:00

LibDraw: Add orientation-based size helpers to Size as well.

Now you can ask for e.g Size::primary_size_for_orientation(Orientation).
This commit is contained in:
Andreas Kling 2019-07-20 22:16:40 +02:00
parent c59b053ad6
commit 2a14ba99a7
2 changed files with 31 additions and 25 deletions

View file

@ -2,6 +2,7 @@
#include <AK/AKString.h>
#include <AK/LogStream.h>
#include <LibDraw/Orientation.h>
struct WSAPI_Size;
@ -50,6 +51,32 @@ public:
return *this;
}
int primary_size_for_orientation(Orientation orientation) const
{
return orientation == Orientation::Vertical ? height() : width();
}
void set_primary_size_for_orientation(Orientation orientation, int value)
{
if (orientation == Orientation::Vertical)
set_height(value);
else
set_width(value);
}
int secondary_size_for_orientation(Orientation orientation) const
{
return orientation == Orientation::Vertical ? width() : height();
}
void set_secondary_size_for_orientation(Orientation orientation, int value)
{
if (orientation == Orientation::Vertical)
set_width(value);
else
set_height(value);
}
operator WSAPI_Size() const;
String to_string() const { return String::format("[%dx%d]", m_width, m_height); }