1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:17:45 +00:00

GVariant: Try to do color string parsing in GVariant::to_color()

If the underlying variant type is a String, try to parse out a color
when to_color() is called.

This makes VisualBuilder apply the saved colors when loading forms.
This commit is contained in:
Andreas Kling 2019-08-03 11:34:02 +02:00
parent e43b27a3fa
commit 54c77cb714

View file

@ -167,17 +167,15 @@ public:
return Color::from_rgba(m_value.as_color);
}
Color to_color() const
{
if (is_color())
return as_color();
return Color();
}
Color to_color(Color default_value) const
Color to_color(Color default_value = {}) const
{
if (type() == Type::Color)
return as_color();
if (type() == Type::String) {
auto color = Color::from_string(as_string());
if (color.has_value())
return color.value();
}
return default_value;
}