mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibDraw: Add orientation-based offset/size manipulation helpers.
These are useful when doing widgets that can be switched between vertical and horizontal mode, such as GSlider. The idea is that instead of using "x" and "y" directly, you use the "primary" and "secondary" offset/size for the Orientation you're configured in.
This commit is contained in:
parent
26e252b0f8
commit
8ab1923abe
2 changed files with 73 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/LogStream.h>
|
||||
#include <LibDraw/Orientation.h>
|
||||
|
||||
class Rect;
|
||||
struct WSAPI_Point;
|
||||
|
@ -68,6 +69,32 @@ public:
|
|||
|
||||
bool is_null() const { return !m_x && !m_y; }
|
||||
|
||||
int primary_offset_for_orientation(Orientation orientation) const
|
||||
{
|
||||
return orientation == Orientation::Vertical ? y() : x();
|
||||
}
|
||||
|
||||
void set_primary_offset_for_orientation(Orientation orientation, int value)
|
||||
{
|
||||
if (orientation == Orientation::Vertical)
|
||||
set_y(value);
|
||||
else
|
||||
set_x(value);
|
||||
}
|
||||
|
||||
int secondary_offset_for_orientation(Orientation orientation) const
|
||||
{
|
||||
return orientation == Orientation::Vertical ? x() : y();
|
||||
}
|
||||
|
||||
void set_secondary_offset_for_orientation(Orientation orientation, int value)
|
||||
{
|
||||
if (orientation == Orientation::Vertical)
|
||||
set_x(value);
|
||||
else
|
||||
set_y(value);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_x { 0 };
|
||||
int m_y { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue