mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:38:11 +00:00
LibGUI: Make it possible to wrap a Font in a GVariant
This commit is contained in:
parent
2638a94094
commit
b89f64cb55
2 changed files with 29 additions and 1 deletions
|
@ -16,6 +16,7 @@ const char* to_string(GVariant::Type type)
|
||||||
case GVariant::Type::Point: return "Point";
|
case GVariant::Type::Point: return "Point";
|
||||||
case GVariant::Type::Size: return "Size";
|
case GVariant::Type::Size: return "Size";
|
||||||
case GVariant::Type::Rect: return "Rect";
|
case GVariant::Type::Rect: return "Rect";
|
||||||
|
case GVariant::Type::Font: return "Font";
|
||||||
}
|
}
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -134,6 +135,13 @@ GVariant::GVariant(const GIcon& value)
|
||||||
AK::ref_if_not_null(m_value.as_icon);
|
AK::ref_if_not_null(m_value.as_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GVariant::GVariant(const Font& value)
|
||||||
|
: m_type(Type::Font)
|
||||||
|
{
|
||||||
|
m_value.as_font = &const_cast<Font&>(value);
|
||||||
|
AK::ref_if_not_null(m_value.as_font);
|
||||||
|
}
|
||||||
|
|
||||||
GVariant::GVariant(Color color)
|
GVariant::GVariant(Color color)
|
||||||
: m_type(Type::Color)
|
: m_type(Type::Color)
|
||||||
{
|
{
|
||||||
|
@ -212,6 +220,10 @@ void GVariant::copy_from(const GVariant& other)
|
||||||
m_value.as_icon = other.m_value.as_icon;
|
m_value.as_icon = other.m_value.as_icon;
|
||||||
AK::ref_if_not_null(m_value.as_icon);
|
AK::ref_if_not_null(m_value.as_icon);
|
||||||
break;
|
break;
|
||||||
|
case Type::Font:
|
||||||
|
m_value.as_font = other.m_value.as_font;
|
||||||
|
AK::ref_if_not_null(m_value.as_font);
|
||||||
|
break;
|
||||||
case Type::Color:
|
case Type::Color:
|
||||||
m_value.as_color = other.m_value.as_color;
|
m_value.as_color = other.m_value.as_color;
|
||||||
break;
|
break;
|
||||||
|
@ -256,6 +268,8 @@ bool GVariant::operator==(const GVariant& other) const
|
||||||
return as_size() == other.as_size();
|
return as_size() == other.as_size();
|
||||||
case Type::Rect:
|
case Type::Rect:
|
||||||
return as_rect() == other.as_rect();
|
return as_rect() == other.as_rect();
|
||||||
|
case Type::Font:
|
||||||
|
return &as_font() == &other.as_font();
|
||||||
case Type::Invalid:
|
case Type::Invalid:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -288,6 +302,7 @@ bool GVariant::operator<(const GVariant& other) const
|
||||||
case Type::Point:
|
case Type::Point:
|
||||||
case Type::Size:
|
case Type::Size:
|
||||||
case Type::Rect:
|
case Type::Rect:
|
||||||
|
case Type::Font:
|
||||||
// FIXME: Figure out how to compare these.
|
// FIXME: Figure out how to compare these.
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
case Type::Invalid:
|
case Type::Invalid:
|
||||||
|
@ -321,6 +336,8 @@ String GVariant::to_string() const
|
||||||
return as_size().to_string();
|
return as_size().to_string();
|
||||||
case Type::Rect:
|
case Type::Rect:
|
||||||
return as_rect().to_string();
|
return as_rect().to_string();
|
||||||
|
case Type::Font:
|
||||||
|
return String::format("[Font: %s]", as_font().name().characters());
|
||||||
case Type::Invalid:
|
case Type::Invalid:
|
||||||
return "[null]";
|
return "[null]";
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibGUI/GIcon.h>
|
#include <LibDraw/Font.h>
|
||||||
#include <LibDraw/GraphicsBitmap.h>
|
#include <LibDraw/GraphicsBitmap.h>
|
||||||
|
#include <LibGUI/GIcon.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
class JsonValue;
|
class JsonValue;
|
||||||
|
@ -22,6 +23,7 @@ public:
|
||||||
GVariant(const Point&);
|
GVariant(const Point&);
|
||||||
GVariant(const Size&);
|
GVariant(const Size&);
|
||||||
GVariant(const Rect&);
|
GVariant(const Rect&);
|
||||||
|
GVariant(const Font&);
|
||||||
GVariant(const AK::JsonValue&);
|
GVariant(const AK::JsonValue&);
|
||||||
GVariant(Color);
|
GVariant(Color);
|
||||||
|
|
||||||
|
@ -47,6 +49,7 @@ public:
|
||||||
Point,
|
Point,
|
||||||
Size,
|
Size,
|
||||||
Rect,
|
Rect,
|
||||||
|
Font,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_valid() const { return m_type != Type::Invalid; }
|
bool is_valid() const { return m_type != Type::Invalid; }
|
||||||
|
@ -61,6 +64,7 @@ public:
|
||||||
bool is_point() const { return m_type == Type::Point; }
|
bool is_point() const { return m_type == Type::Point; }
|
||||||
bool is_size() const { return m_type == Type::Size; }
|
bool is_size() const { return m_type == Type::Size; }
|
||||||
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; }
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
|
||||||
bool as_bool() const
|
bool as_bool() const
|
||||||
|
@ -167,6 +171,12 @@ public:
|
||||||
return Color::from_rgba(m_value.as_color);
|
return Color::from_rgba(m_value.as_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Font& as_font() const
|
||||||
|
{
|
||||||
|
ASSERT(type() == Type::Font);
|
||||||
|
return *m_value.as_font;
|
||||||
|
}
|
||||||
|
|
||||||
Color to_color(Color default_value = {}) const
|
Color to_color(Color default_value = {}) const
|
||||||
{
|
{
|
||||||
if (type() == Type::Color)
|
if (type() == Type::Color)
|
||||||
|
@ -206,6 +216,7 @@ private:
|
||||||
StringImpl* as_string;
|
StringImpl* as_string;
|
||||||
GraphicsBitmap* as_bitmap;
|
GraphicsBitmap* as_bitmap;
|
||||||
GIconImpl* as_icon;
|
GIconImpl* as_icon;
|
||||||
|
Font* as_font;
|
||||||
bool as_bool;
|
bool as_bool;
|
||||||
int as_int;
|
int as_int;
|
||||||
unsigned as_uint;
|
unsigned as_uint;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue