mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 08:17:35 +00:00
LibGfx: Add FlagRole to GUI::Variant
This commit is contained in:
parent
d68268f791
commit
f22043a225
3 changed files with 43 additions and 0 deletions
|
@ -48,6 +48,8 @@ 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::FlagRole:
|
||||||
|
return "FlagRole";
|
||||||
case Variant::Type::MetricRole:
|
case Variant::Type::MetricRole:
|
||||||
return "MetricRole";
|
return "MetricRole";
|
||||||
case Variant::Type::PathRole:
|
case Variant::Type::PathRole:
|
||||||
|
@ -97,6 +99,12 @@ Variant::Variant(Gfx::ColorRole value)
|
||||||
m_value.as_color_role = value;
|
m_value.as_color_role = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant::Variant(Gfx::FlagRole value)
|
||||||
|
: m_type(Type::FlagRole)
|
||||||
|
{
|
||||||
|
m_value.as_flag_role = value;
|
||||||
|
}
|
||||||
|
|
||||||
Variant::Variant(Gfx::MetricRole value)
|
Variant::Variant(Gfx::MetricRole value)
|
||||||
: m_type(Type::MetricRole)
|
: m_type(Type::MetricRole)
|
||||||
{
|
{
|
||||||
|
@ -347,6 +355,9 @@ 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::FlagRole:
|
||||||
|
m_value.as_flag_role = other.m_value.as_flag_role;
|
||||||
|
break;
|
||||||
case Type::MetricRole:
|
case Type::MetricRole:
|
||||||
m_value.as_metric_role = other.m_value.as_metric_role;
|
m_value.as_metric_role = other.m_value.as_metric_role;
|
||||||
break;
|
break;
|
||||||
|
@ -395,6 +406,8 @@ 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::FlagRole:
|
||||||
|
return m_value.as_flag_role == other.m_value.as_flag_role;
|
||||||
case Type::MetricRole:
|
case Type::MetricRole:
|
||||||
return m_value.as_metric_role == other.m_value.as_metric_role;
|
return m_value.as_metric_role == other.m_value.as_metric_role;
|
||||||
case Type::PathRole:
|
case Type::PathRole:
|
||||||
|
@ -438,6 +451,7 @@ 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::FlagRole:
|
||||||
case Type::MetricRole:
|
case Type::MetricRole:
|
||||||
case Type::PathRole:
|
case Type::PathRole:
|
||||||
// FIXME: Figure out how to compare these.
|
// FIXME: Figure out how to compare these.
|
||||||
|
@ -498,6 +512,8 @@ String Variant::to_string() const
|
||||||
}
|
}
|
||||||
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::FlagRole:
|
||||||
|
return String::formatted("Gfx::FlagRole::{}", Gfx::to_string(m_value.as_flag_role));
|
||||||
case Type::MetricRole:
|
case Type::MetricRole:
|
||||||
return String::formatted("Gfx::MetricRole::{}", Gfx::to_string(m_value.as_metric_role));
|
return String::formatted("Gfx::MetricRole::{}", Gfx::to_string(m_value.as_metric_role));
|
||||||
case Type::PathRole:
|
case Type::PathRole:
|
||||||
|
|
|
@ -35,6 +35,7 @@ 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::FlagRole);
|
||||||
Variant(const Gfx::MetricRole);
|
Variant(const Gfx::MetricRole);
|
||||||
Variant(const Gfx::PathRole);
|
Variant(const Gfx::PathRole);
|
||||||
Variant(const JsonValue&);
|
Variant(const JsonValue&);
|
||||||
|
@ -67,6 +68,7 @@ public:
|
||||||
Font,
|
Font,
|
||||||
TextAlignment,
|
TextAlignment,
|
||||||
ColorRole,
|
ColorRole,
|
||||||
|
FlagRole,
|
||||||
MetricRole,
|
MetricRole,
|
||||||
PathRole,
|
PathRole,
|
||||||
};
|
};
|
||||||
|
@ -88,6 +90,7 @@ 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_flag_role() const { return m_type == Type::FlagRole; }
|
||||||
bool is_metric_role() const { return m_type == Type::MetricRole; }
|
bool is_metric_role() const { return m_type == Type::MetricRole; }
|
||||||
bool is_path_role() const { return m_type == Type::PathRole; }
|
bool is_path_role() const { return m_type == Type::PathRole; }
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
@ -251,6 +254,13 @@ public:
|
||||||
return m_value.as_color_role;
|
return m_value.as_color_role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gfx::FlagRole to_flag_role() const
|
||||||
|
{
|
||||||
|
if (type() != Type::FlagRole)
|
||||||
|
return Gfx::FlagRole::NoRole;
|
||||||
|
return m_value.as_flag_role;
|
||||||
|
}
|
||||||
|
|
||||||
Gfx::MetricRole to_metric_role() const
|
Gfx::MetricRole to_metric_role() const
|
||||||
{
|
{
|
||||||
if (type() != Type::MetricRole)
|
if (type() != Type::MetricRole)
|
||||||
|
@ -315,6 +325,7 @@ 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::FlagRole as_flag_role;
|
||||||
Gfx::MetricRole as_metric_role;
|
Gfx::MetricRole as_metric_role;
|
||||||
Gfx::PathRole as_path_role;
|
Gfx::PathRole as_path_role;
|
||||||
RawPoint as_point;
|
RawPoint as_point;
|
||||||
|
|
|
@ -147,6 +147,22 @@ enum class FlagRole {
|
||||||
__Count,
|
__Count,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline const char* to_string(FlagRole role)
|
||||||
|
{
|
||||||
|
switch (role) {
|
||||||
|
case FlagRole::NoRole:
|
||||||
|
return "NoRole";
|
||||||
|
#undef __ENUMERATE_FLAG_ROLE
|
||||||
|
#define __ENUMERATE_FLAG_ROLE(role) \
|
||||||
|
case FlagRole::role: \
|
||||||
|
return #role;
|
||||||
|
ENUMERATE_FLAG_ROLES(__ENUMERATE_FLAG_ROLE)
|
||||||
|
#undef __ENUMERATE_FLAG_ROLE
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum class MetricRole {
|
enum class MetricRole {
|
||||||
NoRole,
|
NoRole,
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue