1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:37:35 +00:00

LibGUI: Add Gfx::ColorRole to Variant

For Theme Editor. :^)
This commit is contained in:
Karol Kosek 2021-09-05 21:38:36 +02:00 committed by Ali Mohammad Pur
parent c1ede97543
commit 759d6df87d
2 changed files with 29 additions and 0 deletions

View file

@ -46,6 +46,8 @@ const char* to_string(Variant::Type type)
return "Font"; return "Font";
case Variant::Type::TextAlignment: case Variant::Type::TextAlignment:
return "TextAlignment"; return "TextAlignment";
case Variant::Type::ColorRole:
return "ColorRole";
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
@ -85,6 +87,12 @@ Variant::Variant(Gfx::TextAlignment value)
m_value.as_text_alignment = value; m_value.as_text_alignment = value;
} }
Variant::Variant(Gfx::ColorRole value)
: m_type(Type::ColorRole)
{
m_value.as_color_role = value;
}
Variant::Variant(i32 value) Variant::Variant(i32 value)
: m_type(Type::Int32) : m_type(Type::Int32)
{ {
@ -320,6 +328,9 @@ void Variant::copy_from(const Variant& other)
case Type::TextAlignment: case Type::TextAlignment:
m_value.as_text_alignment = other.m_value.as_text_alignment; m_value.as_text_alignment = other.m_value.as_text_alignment;
break; break;
case Type::ColorRole:
m_value.as_color_role = other.m_value.as_color_role;
break;
case Type::Invalid: case Type::Invalid:
break; break;
} }
@ -360,6 +371,8 @@ bool Variant::operator==(const Variant& other) const
return &as_font() == &other.as_font(); return &as_font() == &other.as_font();
case Type::TextAlignment: case Type::TextAlignment:
return m_value.as_text_alignment == other.m_value.as_text_alignment; return m_value.as_text_alignment == other.m_value.as_text_alignment;
case Type::ColorRole:
return m_value.as_color_role == other.m_value.as_color_role;
case Type::Invalid: case Type::Invalid:
return true; return true;
} }
@ -398,6 +411,7 @@ bool Variant::operator<(const Variant& other) const
case Type::Rect: case Type::Rect:
case Type::Font: case Type::Font:
case Type::TextAlignment: case Type::TextAlignment:
case Type::ColorRole:
// FIXME: Figure out how to compare these. // FIXME: Figure out how to compare these.
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
case Type::Invalid: case Type::Invalid:
@ -454,6 +468,9 @@ String Variant::to_string() const
} }
return ""; return "";
} }
case Type::ColorRole: {
return String::formatted("Gfx::ColorRole::{}", Gfx::to_string(m_value.as_color_role));
}
case Type::Invalid: case Type::Invalid:
return "[null]"; return "[null]";
} }

View file

@ -10,6 +10,7 @@
#include <LibGUI/Icon.h> #include <LibGUI/Icon.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
#include <LibGfx/Font.h> #include <LibGfx/Font.h>
#include <LibGfx/SystemTheme.h>
namespace GUI { namespace GUI {
@ -33,6 +34,7 @@ public:
Variant(const Gfx::IntRect&); Variant(const Gfx::IntRect&);
Variant(const Gfx::Font&); Variant(const Gfx::Font&);
Variant(const Gfx::TextAlignment); Variant(const Gfx::TextAlignment);
Variant(const Gfx::ColorRole);
Variant(const JsonValue&); Variant(const JsonValue&);
Variant(Color); Variant(Color);
@ -62,6 +64,7 @@ public:
Rect, Rect,
Font, Font,
TextAlignment, TextAlignment,
ColorRole,
}; };
bool is_valid() const { return m_type != Type::Invalid; } bool is_valid() const { return m_type != Type::Invalid; }
@ -80,6 +83,7 @@ public:
bool is_rect() const { return m_type == Type::Rect; } bool is_rect() const { return m_type == Type::Rect; }
bool is_font() const { return m_type == Type::Font; } bool is_font() const { return m_type == Type::Font; }
bool is_text_alignment() const { return m_type == Type::TextAlignment; } bool is_text_alignment() const { return m_type == Type::TextAlignment; }
bool is_color_role() const { return m_type == Type::ColorRole; }
Type type() const { return m_type; } Type type() const { return m_type; }
bool as_bool() const bool as_bool() const
@ -234,6 +238,13 @@ public:
return m_value.as_text_alignment; return m_value.as_text_alignment;
} }
Gfx::ColorRole to_color_role() const
{
if (type() != Type::ColorRole)
return Gfx::ColorRole::NoRole;
return m_value.as_color_role;
}
Color to_color(Color default_value = {}) const Color to_color(Color default_value = {}) const
{ {
if (type() == Type::Color) if (type() == Type::Color)
@ -283,6 +294,7 @@ private:
float as_float; float as_float;
Gfx::RGBA32 as_color; Gfx::RGBA32 as_color;
Gfx::TextAlignment as_text_alignment; Gfx::TextAlignment as_text_alignment;
Gfx::ColorRole as_color_role;
RawPoint as_point; RawPoint as_point;
RawSize as_size; RawSize as_size;
RawRect as_rect; RawRect as_rect;