2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-03-22 18:06:31 +00:00
|
|
|
#include <AK/FlyString.h>
|
2019-06-29 10:06:26 +00:00
|
|
|
#include <AK/JsonValue.h>
|
2020-12-03 11:44:00 +00:00
|
|
|
#include <AK/RefPtr.h>
|
2020-02-06 19:33:02 +00:00
|
|
|
#include <LibGUI/Variant.h>
|
2019-02-28 15:20:29 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
const char* to_string(Variant::Type type)
|
2019-06-23 05:54:46 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Invalid:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Invalid";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Bool:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Bool";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Int32:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Int32";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Int64:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Int64";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::UnsignedInt:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "UnsignedInt";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Float:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Float";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::String:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "String";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Bitmap:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Bitmap";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Color:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Color";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Icon:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Icon";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Point:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Point";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Size:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Size";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Rect:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Rect";
|
2020-02-02 14:07:41 +00:00
|
|
|
case Variant::Type::Font:
|
2020-01-27 09:55:10 +00:00
|
|
|
return "Font";
|
2020-05-21 17:36:09 +00:00
|
|
|
case Variant::Type::TextAlignment:
|
|
|
|
return "TextAlignment";
|
2019-06-23 05:54:46 +00:00
|
|
|
}
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-06-23 05:54:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant()
|
2019-03-18 03:54:07 +00:00
|
|
|
{
|
2019-04-11 15:28:59 +00:00
|
|
|
m_value.as_string = nullptr;
|
2019-03-18 03:54:07 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::~Variant()
|
2019-04-12 12:43:44 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Variant::clear()
|
2019-02-28 15:20:29 +00:00
|
|
|
{
|
|
|
|
switch (m_type) {
|
|
|
|
case Type::String:
|
2020-01-23 14:14:21 +00:00
|
|
|
AK::unref_if_not_null(m_value.as_string);
|
2019-02-28 15:20:29 +00:00
|
|
|
break;
|
|
|
|
case Type::Bitmap:
|
2020-01-23 14:14:21 +00:00
|
|
|
AK::unref_if_not_null(m_value.as_bitmap);
|
2019-02-28 15:20:29 +00:00
|
|
|
break;
|
2019-03-24 03:28:36 +00:00
|
|
|
case Type::Icon:
|
2020-01-23 14:14:21 +00:00
|
|
|
AK::unref_if_not_null(m_value.as_icon);
|
2019-03-24 03:28:36 +00:00
|
|
|
break;
|
2019-02-28 15:20:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-04-12 12:43:44 +00:00
|
|
|
m_type = Type::Invalid;
|
|
|
|
m_value.as_string = nullptr;
|
2019-02-28 15:20:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 17:36:09 +00:00
|
|
|
Variant::Variant(Gfx::TextAlignment value)
|
|
|
|
: m_type(Type::TextAlignment)
|
|
|
|
{
|
|
|
|
m_value.as_text_alignment = value;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(i32 value)
|
2020-01-27 09:55:10 +00:00
|
|
|
: m_type(Type::Int32)
|
2019-02-28 15:20:29 +00:00
|
|
|
{
|
2020-01-27 09:55:10 +00:00
|
|
|
m_value.as_i32 = value;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(i64 value)
|
2020-01-27 09:55:10 +00:00
|
|
|
: m_type(Type::Int64)
|
|
|
|
{
|
|
|
|
m_value.as_i64 = value;
|
2019-02-28 15:20:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(unsigned value)
|
2019-07-31 05:07:59 +00:00
|
|
|
: m_type(Type::UnsignedInt)
|
|
|
|
{
|
|
|
|
m_value.as_uint = value;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(float value)
|
2019-02-28 15:20:29 +00:00
|
|
|
: m_type(Type::Float)
|
|
|
|
{
|
|
|
|
m_value.as_float = value;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(bool value)
|
2019-02-28 15:20:29 +00:00
|
|
|
: m_type(Type::Bool)
|
|
|
|
{
|
|
|
|
m_value.as_bool = value;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(const char* cstring)
|
|
|
|
: Variant(String(cstring))
|
2019-06-22 08:37:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:06:31 +00:00
|
|
|
Variant::Variant(const FlyString& value)
|
|
|
|
: Variant(String(value.impl()))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(const String& value)
|
2019-02-28 15:20:29 +00:00
|
|
|
: m_type(Type::String)
|
|
|
|
{
|
|
|
|
m_value.as_string = const_cast<StringImpl*>(value.impl());
|
2019-06-21 13:29:31 +00:00
|
|
|
AK::ref_if_not_null(m_value.as_string);
|
2019-02-28 15:20:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(const JsonValue& value)
|
2019-06-29 10:06:26 +00:00
|
|
|
{
|
|
|
|
if (value.is_null()) {
|
|
|
|
m_value.as_string = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-29 15:36:50 +00:00
|
|
|
if (value.is_i32()) {
|
2020-01-27 09:55:10 +00:00
|
|
|
m_type = Type::Int32;
|
|
|
|
m_value.as_i32 = value.as_i32();
|
2019-06-29 10:06:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-29 15:36:50 +00:00
|
|
|
if (value.is_u32()) {
|
2019-07-31 05:07:59 +00:00
|
|
|
m_type = Type::UnsignedInt;
|
2019-10-29 15:36:50 +00:00
|
|
|
m_value.as_uint = value.as_u32();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value.is_i64()) {
|
2020-01-27 09:55:10 +00:00
|
|
|
m_type = Type::Int64;
|
|
|
|
m_value.as_i64 = value.as_i64();
|
2019-10-29 15:36:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value.is_u64()) {
|
2020-02-02 14:07:41 +00:00
|
|
|
// FIXME: Variant should have a 64-bit internal type.
|
2019-10-29 15:36:50 +00:00
|
|
|
m_type = Type::UnsignedInt;
|
|
|
|
m_value.as_uint = value.to_u32();
|
2019-06-29 10:06:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value.is_string()) {
|
|
|
|
m_type = Type::String;
|
|
|
|
m_value.as_string = value.as_string().impl();
|
|
|
|
m_value.as_string->ref();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value.is_bool()) {
|
|
|
|
m_type = Type::Bool;
|
|
|
|
m_value.as_bool = value.as_bool();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-06-29 10:06:26 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
Variant::Variant(const Gfx::Bitmap& value)
|
2019-02-28 15:20:29 +00:00
|
|
|
: m_type(Type::Bitmap)
|
|
|
|
{
|
2020-02-06 10:56:38 +00:00
|
|
|
m_value.as_bitmap = const_cast<Gfx::Bitmap*>(&value);
|
2019-06-21 13:29:31 +00:00
|
|
|
AK::ref_if_not_null(m_value.as_bitmap);
|
2019-02-28 15:20:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 23:02:21 +00:00
|
|
|
Variant::Variant(const GUI::Icon& value)
|
2019-03-24 03:28:36 +00:00
|
|
|
: m_type(Type::Icon)
|
|
|
|
{
|
2020-03-06 23:02:21 +00:00
|
|
|
m_value.as_icon = &const_cast<GUI::IconImpl&>(value.impl());
|
2019-06-21 13:29:31 +00:00
|
|
|
AK::ref_if_not_null(m_value.as_icon);
|
2019-03-24 03:28:36 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
Variant::Variant(const Gfx::Font& value)
|
2019-10-22 19:37:11 +00:00
|
|
|
: m_type(Type::Font)
|
|
|
|
{
|
2020-02-06 10:56:38 +00:00
|
|
|
m_value.as_font = &const_cast<Gfx::Font&>(value);
|
2019-10-22 19:37:11 +00:00
|
|
|
AK::ref_if_not_null(m_value.as_font);
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(Color color)
|
2019-03-18 03:54:07 +00:00
|
|
|
: m_type(Type::Color)
|
|
|
|
{
|
|
|
|
m_value.as_color = color.value();
|
|
|
|
}
|
|
|
|
|
2020-06-10 08:57:59 +00:00
|
|
|
Variant::Variant(const Gfx::IntPoint& point)
|
2019-04-11 20:52:34 +00:00
|
|
|
: m_type(Type::Point)
|
|
|
|
{
|
|
|
|
m_value.as_point = { point.x(), point.y() };
|
|
|
|
}
|
|
|
|
|
2020-06-10 08:57:59 +00:00
|
|
|
Variant::Variant(const Gfx::IntSize& size)
|
2019-04-11 20:52:34 +00:00
|
|
|
: m_type(Type::Size)
|
|
|
|
{
|
|
|
|
m_value.as_size = { size.width(), size.height() };
|
|
|
|
}
|
|
|
|
|
2020-06-10 08:57:59 +00:00
|
|
|
Variant::Variant(const Gfx::IntRect& rect)
|
2019-04-11 20:52:34 +00:00
|
|
|
: m_type(Type::Rect)
|
|
|
|
{
|
|
|
|
m_value.as_rect = (const RawRect&)rect;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant& Variant::operator=(const Variant& other)
|
2019-04-12 12:43:44 +00:00
|
|
|
{
|
|
|
|
if (&other == this)
|
|
|
|
return *this;
|
|
|
|
clear();
|
|
|
|
copy_from(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant& Variant::operator=(Variant&& other)
|
2019-04-18 23:05:59 +00:00
|
|
|
{
|
|
|
|
if (&other == this)
|
|
|
|
return *this;
|
|
|
|
clear();
|
2021-02-25 20:10:47 +00:00
|
|
|
move_from(move(other));
|
2019-04-18 23:05:59 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Variant::Variant(const Variant& other)
|
2019-04-11 19:36:04 +00:00
|
|
|
{
|
2019-04-12 12:43:44 +00:00
|
|
|
copy_from(other);
|
|
|
|
}
|
|
|
|
|
2020-12-03 11:44:00 +00:00
|
|
|
void Variant::move_from(Variant&& other)
|
|
|
|
{
|
|
|
|
m_type = other.m_type;
|
|
|
|
m_value = other.m_value;
|
|
|
|
other.m_type = Type::Invalid;
|
|
|
|
other.m_value.as_string = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Variant::copy_from(const Variant& other)
|
2019-04-12 12:43:44 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(!is_valid());
|
2019-04-12 12:43:44 +00:00
|
|
|
m_type = other.m_type;
|
2019-04-11 19:36:04 +00:00
|
|
|
switch (m_type) {
|
|
|
|
case Type::Bool:
|
|
|
|
m_value.as_bool = other.m_value.as_bool;
|
|
|
|
break;
|
2020-01-27 09:55:10 +00:00
|
|
|
case Type::Int32:
|
|
|
|
m_value.as_i32 = other.m_value.as_i32;
|
|
|
|
break;
|
|
|
|
case Type::Int64:
|
|
|
|
m_value.as_i64 = other.m_value.as_i64;
|
2019-04-11 19:36:04 +00:00
|
|
|
break;
|
2019-07-31 05:07:59 +00:00
|
|
|
case Type::UnsignedInt:
|
|
|
|
m_value.as_uint = other.m_value.as_uint;
|
|
|
|
break;
|
2019-04-11 19:36:04 +00:00
|
|
|
case Type::Float:
|
|
|
|
m_value.as_float = other.m_value.as_float;
|
|
|
|
break;
|
|
|
|
case Type::String:
|
|
|
|
m_value.as_string = other.m_value.as_string;
|
2019-06-21 13:29:31 +00:00
|
|
|
AK::ref_if_not_null(m_value.as_bitmap);
|
2019-04-11 19:36:04 +00:00
|
|
|
break;
|
|
|
|
case Type::Bitmap:
|
|
|
|
m_value.as_bitmap = other.m_value.as_bitmap;
|
2019-06-21 13:29:31 +00:00
|
|
|
AK::ref_if_not_null(m_value.as_bitmap);
|
2019-04-11 19:36:04 +00:00
|
|
|
break;
|
|
|
|
case Type::Icon:
|
|
|
|
m_value.as_icon = other.m_value.as_icon;
|
2019-06-21 13:29:31 +00:00
|
|
|
AK::ref_if_not_null(m_value.as_icon);
|
2019-04-11 19:36:04 +00:00
|
|
|
break;
|
2019-10-22 19:37:11 +00:00
|
|
|
case Type::Font:
|
|
|
|
m_value.as_font = other.m_value.as_font;
|
|
|
|
AK::ref_if_not_null(m_value.as_font);
|
|
|
|
break;
|
2019-04-11 19:36:04 +00:00
|
|
|
case Type::Color:
|
|
|
|
m_value.as_color = other.m_value.as_color;
|
|
|
|
break;
|
2019-04-11 20:52:34 +00:00
|
|
|
case Type::Point:
|
|
|
|
m_value.as_point = other.m_value.as_point;
|
|
|
|
break;
|
|
|
|
case Type::Size:
|
|
|
|
m_value.as_size = other.m_value.as_size;
|
|
|
|
break;
|
|
|
|
case Type::Rect:
|
|
|
|
m_value.as_rect = other.m_value.as_rect;
|
|
|
|
break;
|
2020-05-21 17:36:09 +00:00
|
|
|
case Type::TextAlignment:
|
|
|
|
m_value.as_text_alignment = other.m_value.as_text_alignment;
|
|
|
|
break;
|
2019-04-11 19:36:04 +00:00
|
|
|
case Type::Invalid:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
bool Variant::operator==(const Variant& other) const
|
2019-03-09 12:33:52 +00:00
|
|
|
{
|
|
|
|
if (m_type != other.m_type)
|
|
|
|
return to_string() == other.to_string();
|
|
|
|
switch (m_type) {
|
|
|
|
case Type::Bool:
|
|
|
|
return as_bool() == other.as_bool();
|
2020-01-27 09:55:10 +00:00
|
|
|
case Type::Int32:
|
|
|
|
return as_i32() == other.as_i32();
|
|
|
|
case Type::Int64:
|
|
|
|
return as_i64() == other.as_i64();
|
2019-07-31 05:07:59 +00:00
|
|
|
case Type::UnsignedInt:
|
|
|
|
return as_uint() == other.as_uint();
|
2019-03-09 12:33:52 +00:00
|
|
|
case Type::Float:
|
|
|
|
return as_float() == other.as_float();
|
|
|
|
case Type::String:
|
|
|
|
return as_string() == other.as_string();
|
|
|
|
case Type::Bitmap:
|
|
|
|
return m_value.as_bitmap == other.m_value.as_bitmap;
|
2019-03-24 03:28:36 +00:00
|
|
|
case Type::Icon:
|
|
|
|
return m_value.as_icon == other.m_value.as_icon;
|
2019-03-18 03:54:07 +00:00
|
|
|
case Type::Color:
|
|
|
|
return m_value.as_color == other.m_value.as_color;
|
2019-04-11 20:52:34 +00:00
|
|
|
case Type::Point:
|
|
|
|
return as_point() == other.as_point();
|
|
|
|
case Type::Size:
|
|
|
|
return as_size() == other.as_size();
|
|
|
|
case Type::Rect:
|
|
|
|
return as_rect() == other.as_rect();
|
2019-10-22 19:37:11 +00:00
|
|
|
case Type::Font:
|
|
|
|
return &as_font() == &other.as_font();
|
2020-05-21 17:36:09 +00:00
|
|
|
case Type::TextAlignment:
|
|
|
|
return m_value.as_text_alignment == other.m_value.as_text_alignment;
|
2019-03-09 12:33:52 +00:00
|
|
|
case Type::Invalid:
|
2019-06-29 10:06:26 +00:00
|
|
|
return true;
|
2019-03-09 12:33:52 +00:00
|
|
|
}
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-03-09 12:33:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
bool Variant::operator<(const Variant& other) const
|
2019-03-09 12:33:52 +00:00
|
|
|
{
|
|
|
|
if (m_type != other.m_type)
|
|
|
|
return to_string() < other.to_string();
|
|
|
|
switch (m_type) {
|
|
|
|
case Type::Bool:
|
|
|
|
return as_bool() < other.as_bool();
|
2020-01-27 09:55:10 +00:00
|
|
|
case Type::Int32:
|
|
|
|
return as_i32() < other.as_i32();
|
|
|
|
case Type::Int64:
|
|
|
|
return as_i64() < other.as_i64();
|
2019-07-31 05:07:59 +00:00
|
|
|
case Type::UnsignedInt:
|
|
|
|
return as_uint() < other.as_uint();
|
2019-03-09 12:33:52 +00:00
|
|
|
case Type::Float:
|
|
|
|
return as_float() < other.as_float();
|
|
|
|
case Type::String:
|
|
|
|
return as_string() < other.as_string();
|
|
|
|
case Type::Bitmap:
|
|
|
|
// FIXME: Maybe compare bitmaps somehow differently?
|
|
|
|
return m_value.as_bitmap < other.m_value.as_bitmap;
|
2019-03-24 03:28:36 +00:00
|
|
|
case Type::Icon:
|
|
|
|
// FIXME: Maybe compare icons somehow differently?
|
|
|
|
return m_value.as_icon < other.m_value.as_icon;
|
2019-03-18 03:54:07 +00:00
|
|
|
case Type::Color:
|
|
|
|
return m_value.as_color < other.m_value.as_color;
|
2019-04-11 20:52:34 +00:00
|
|
|
case Type::Point:
|
|
|
|
case Type::Size:
|
|
|
|
case Type::Rect:
|
2019-10-22 19:37:11 +00:00
|
|
|
case Type::Font:
|
2020-05-21 17:36:09 +00:00
|
|
|
case Type::TextAlignment:
|
2019-04-11 20:52:34 +00:00
|
|
|
// FIXME: Figure out how to compare these.
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-03-09 12:33:52 +00:00
|
|
|
case Type::Invalid:
|
|
|
|
break;
|
|
|
|
}
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-03-09 12:33:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
String Variant::to_string() const
|
2019-02-28 15:20:29 +00:00
|
|
|
{
|
|
|
|
switch (m_type) {
|
|
|
|
case Type::Bool:
|
2019-04-12 12:49:45 +00:00
|
|
|
return as_bool() ? "true" : "false";
|
2020-01-27 09:55:10 +00:00
|
|
|
case Type::Int32:
|
|
|
|
return String::number(as_i32());
|
|
|
|
case Type::Int64:
|
|
|
|
return String::number(as_i64());
|
2019-07-31 05:07:59 +00:00
|
|
|
case Type::UnsignedInt:
|
|
|
|
return String::number(as_uint());
|
2019-02-28 15:20:29 +00:00
|
|
|
case Type::Float:
|
2020-04-06 21:27:15 +00:00
|
|
|
return String::format("%.2f", (double)as_float());
|
2019-02-28 15:20:29 +00:00
|
|
|
case Type::String:
|
|
|
|
return as_string();
|
|
|
|
case Type::Bitmap:
|
2020-02-06 11:07:05 +00:00
|
|
|
return "[Gfx::Bitmap]";
|
2019-03-24 03:28:36 +00:00
|
|
|
case Type::Icon:
|
2020-03-06 23:02:21 +00:00
|
|
|
return "[GUI::Icon]";
|
2019-03-18 03:54:07 +00:00
|
|
|
case Type::Color:
|
|
|
|
return as_color().to_string();
|
2019-04-11 20:52:34 +00:00
|
|
|
case Type::Point:
|
|
|
|
return as_point().to_string();
|
|
|
|
case Type::Size:
|
|
|
|
return as_size().to_string();
|
|
|
|
case Type::Rect:
|
|
|
|
return as_rect().to_string();
|
2019-10-22 19:37:11 +00:00
|
|
|
case Type::Font:
|
2021-01-03 13:51:17 +00:00
|
|
|
return String::formatted("[Font: {}]", as_font().name());
|
2020-05-21 17:36:09 +00:00
|
|
|
case Type::TextAlignment: {
|
|
|
|
switch (m_value.as_text_alignment) {
|
|
|
|
case Gfx::TextAlignment::Center:
|
|
|
|
return "Gfx::TextAlignment::Center";
|
|
|
|
case Gfx::TextAlignment::CenterLeft:
|
|
|
|
return "Gfx::TextAlignment::CenterLeft";
|
|
|
|
case Gfx::TextAlignment::CenterRight:
|
|
|
|
return "Gfx::TextAlignment::CenterRight";
|
|
|
|
case Gfx::TextAlignment::TopLeft:
|
|
|
|
return "Gfx::TextAlignment::TopLeft";
|
|
|
|
case Gfx::TextAlignment::TopRight:
|
|
|
|
return "Gfx::TextAlignment::TopRight";
|
|
|
|
default:
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2020-05-21 17:36:09 +00:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2019-02-28 15:20:29 +00:00
|
|
|
case Type::Invalid:
|
2019-04-12 12:49:45 +00:00
|
|
|
return "[null]";
|
2019-02-28 15:20:29 +00:00
|
|
|
}
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-02-28 15:20:29 +00:00
|
|
|
}
|
2020-02-02 14:07:41 +00:00
|
|
|
|
|
|
|
}
|