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

LibGUI: Add MetricRole and PathRole to GUI::Variant

This is needed for making them editable in the ThemeEditor, like
ColorRole is.
This commit is contained in:
Sam Atkins 2021-10-27 16:58:57 +01:00 committed by Andreas Kling
parent 31ce4d04b6
commit 859975f6bd
2 changed files with 55 additions and 2 deletions

View file

@ -48,6 +48,10 @@ const char* to_string(Variant::Type type)
return "TextAlignment"; return "TextAlignment";
case Variant::Type::ColorRole: case Variant::Type::ColorRole:
return "ColorRole"; return "ColorRole";
case Variant::Type::MetricRole:
return "MetricRole";
case Variant::Type::PathRole:
return "PathRole";
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
@ -93,6 +97,18 @@ Variant::Variant(Gfx::ColorRole value)
m_value.as_color_role = 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) Variant::Variant(i32 value)
: m_type(Type::Int32) : m_type(Type::Int32)
{ {
@ -331,6 +347,12 @@ void Variant::copy_from(const Variant& other)
case Type::ColorRole: case Type::ColorRole:
m_value.as_color_role = other.m_value.as_color_role; m_value.as_color_role = other.m_value.as_color_role;
break; 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: case Type::Invalid:
break; break;
} }
@ -373,6 +395,10 @@ bool Variant::operator==(const Variant& other) const
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: case Type::ColorRole:
return m_value.as_color_role == other.m_value.as_color_role; 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: case Type::Invalid:
return true; return true;
} }
@ -412,6 +438,8 @@ bool Variant::operator<(const Variant& other) const
case Type::Font: case Type::Font:
case Type::TextAlignment: case Type::TextAlignment:
case Type::ColorRole: case Type::ColorRole:
case Type::MetricRole:
case Type::PathRole:
// 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:
@ -468,9 +496,12 @@ String Variant::to_string() const
} }
return ""; return "";
} }
case Type::ColorRole: { case Type::ColorRole:
return String::formatted("Gfx::ColorRole::{}", Gfx::to_string(m_value.as_color_role)); 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: case Type::Invalid:
return "[null]"; return "[null]";
} }

View file

@ -35,6 +35,8 @@ public:
Variant(const Gfx::Font&); Variant(const Gfx::Font&);
Variant(const Gfx::TextAlignment); Variant(const Gfx::TextAlignment);
Variant(const Gfx::ColorRole); Variant(const Gfx::ColorRole);
Variant(const Gfx::MetricRole);
Variant(const Gfx::PathRole);
Variant(const JsonValue&); Variant(const JsonValue&);
Variant(Color); Variant(Color);
@ -65,6 +67,8 @@ public:
Font, Font,
TextAlignment, TextAlignment,
ColorRole, ColorRole,
MetricRole,
PathRole,
}; };
bool is_valid() const { return m_type != Type::Invalid; } 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_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; } 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; } Type type() const { return m_type; }
bool as_bool() const bool as_bool() const
@ -245,6 +251,20 @@ public:
return m_value.as_color_role; 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 Color to_color(Color default_value = {}) const
{ {
if (type() == Type::Color) if (type() == Type::Color)
@ -295,6 +315,8 @@ private:
Gfx::RGBA32 as_color; Gfx::RGBA32 as_color;
Gfx::TextAlignment as_text_alignment; Gfx::TextAlignment as_text_alignment;
Gfx::ColorRole as_color_role; Gfx::ColorRole as_color_role;
Gfx::MetricRole as_metric_role;
Gfx::PathRole as_path_role;
RawPoint as_point; RawPoint as_point;
RawSize as_size; RawSize as_size;
RawRect as_rect; RawRect as_rect;