diff --git a/Userland/Libraries/LibGUI/Variant.cpp b/Userland/Libraries/LibGUI/Variant.cpp index e6483396680..3c2aa75f870 100644 --- a/Userland/Libraries/LibGUI/Variant.cpp +++ b/Userland/Libraries/LibGUI/Variant.cpp @@ -48,6 +48,10 @@ const char* to_string(Variant::Type type) return "TextAlignment"; case Variant::Type::ColorRole: return "ColorRole"; + case Variant::Type::MetricRole: + return "MetricRole"; + case Variant::Type::PathRole: + return "PathRole"; } VERIFY_NOT_REACHED(); } @@ -93,6 +97,18 @@ Variant::Variant(Gfx::ColorRole value) m_value.as_color_role = value; } +Variant::Variant(Gfx::MetricRole value) + : m_type(Type::MetricRole) +{ + m_value.as_metric_role = value; +} + +Variant::Variant(Gfx::PathRole value) + : m_type(Type::PathRole) +{ + m_value.as_path_role = value; +} + Variant::Variant(i32 value) : m_type(Type::Int32) { @@ -331,6 +347,12 @@ void Variant::copy_from(const Variant& other) case Type::ColorRole: m_value.as_color_role = other.m_value.as_color_role; break; + case Type::MetricRole: + m_value.as_metric_role = other.m_value.as_metric_role; + break; + case Type::PathRole: + m_value.as_path_role = other.m_value.as_path_role; + break; case Type::Invalid: break; } @@ -373,6 +395,10 @@ bool Variant::operator==(const Variant& other) const 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::MetricRole: + return m_value.as_metric_role == other.m_value.as_metric_role; + case Type::PathRole: + return m_value.as_path_role == other.m_value.as_path_role; case Type::Invalid: return true; } @@ -412,6 +438,8 @@ bool Variant::operator<(const Variant& other) const case Type::Font: case Type::TextAlignment: case Type::ColorRole: + case Type::MetricRole: + case Type::PathRole: // FIXME: Figure out how to compare these. VERIFY_NOT_REACHED(); case Type::Invalid: @@ -468,9 +496,12 @@ String Variant::to_string() const } return ""; } - case Type::ColorRole: { + case Type::ColorRole: return String::formatted("Gfx::ColorRole::{}", Gfx::to_string(m_value.as_color_role)); - } + case Type::MetricRole: + return String::formatted("Gfx::MetricRole::{}", Gfx::to_string(m_value.as_metric_role)); + case Type::PathRole: + return String::formatted("Gfx::PathRole::{}", Gfx::to_string(m_value.as_path_role)); case Type::Invalid: return "[null]"; } diff --git a/Userland/Libraries/LibGUI/Variant.h b/Userland/Libraries/LibGUI/Variant.h index 48fe8826828..7059d9a464e 100644 --- a/Userland/Libraries/LibGUI/Variant.h +++ b/Userland/Libraries/LibGUI/Variant.h @@ -35,6 +35,8 @@ public: Variant(const Gfx::Font&); Variant(const Gfx::TextAlignment); Variant(const Gfx::ColorRole); + Variant(const Gfx::MetricRole); + Variant(const Gfx::PathRole); Variant(const JsonValue&); Variant(Color); @@ -65,6 +67,8 @@ public: Font, TextAlignment, ColorRole, + MetricRole, + PathRole, }; bool is_valid() const { return m_type != Type::Invalid; } @@ -84,6 +88,8 @@ public: bool is_font() const { return m_type == Type::Font; } bool is_text_alignment() const { return m_type == Type::TextAlignment; } bool is_color_role() const { return m_type == Type::ColorRole; } + bool is_metric_role() const { return m_type == Type::MetricRole; } + bool is_path_role() const { return m_type == Type::PathRole; } Type type() const { return m_type; } bool as_bool() const @@ -245,6 +251,20 @@ public: return m_value.as_color_role; } + Gfx::MetricRole to_metric_role() const + { + if (type() != Type::MetricRole) + return Gfx::MetricRole::NoRole; + return m_value.as_metric_role; + } + + Gfx::PathRole to_path_role() const + { + if (type() != Type::PathRole) + return Gfx::PathRole::NoRole; + return m_value.as_path_role; + } + Color to_color(Color default_value = {}) const { if (type() == Type::Color) @@ -295,6 +315,8 @@ private: Gfx::RGBA32 as_color; Gfx::TextAlignment as_text_alignment; Gfx::ColorRole as_color_role; + Gfx::MetricRole as_metric_role; + Gfx::PathRole as_path_role; RawPoint as_point; RawSize as_size; RawRect as_rect;