From 3acbffabf914391cc0834adc16a99367780e82d6 Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Tue, 24 Oct 2023 21:57:19 +0200 Subject: [PATCH] LibGUI: Add double type to Variant --- Userland/Libraries/LibGUI/Variant.cpp | 5 +++++ Userland/Libraries/LibGUI/Variant.h | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/Variant.cpp b/Userland/Libraries/LibGUI/Variant.cpp index e9a4bcd2ec..6646e2cad8 100644 --- a/Userland/Libraries/LibGUI/Variant.cpp +++ b/Userland/Libraries/LibGUI/Variant.cpp @@ -43,6 +43,11 @@ Variant& Variant::operator=(JsonValue const& value) return *this; } + if (value.is_double()) { + set(value.as_double()); + return *this; + } + if (value.is_string()) { set(value.as_string()); return *this; diff --git a/Userland/Libraries/LibGUI/Variant.h b/Userland/Libraries/LibGUI/Variant.h index feb97086f9..eb6b7f7404 100644 --- a/Userland/Libraries/LibGUI/Variant.h +++ b/Userland/Libraries/LibGUI/Variant.h @@ -21,7 +21,7 @@ namespace Detail { struct Boolean { bool value; }; -using VariantUnderlyingType = AK::Variant, NonnullRefPtr, GUI::Icon>; +using VariantUnderlyingType = AK::Variant, NonnullRefPtr, GUI::Icon>; } class Variant : public Detail::VariantUnderlyingType { @@ -76,6 +76,7 @@ public: bool is_u32() const { return has(); } bool is_u64() const { return has(); } bool is_float() const { return has(); } + bool is_double() const { return has(); } bool is_string() const { return has(); } bool is_bitmap() const { return has>(); } bool is_color() const { return has(); } @@ -102,7 +103,7 @@ public: [](Gfx::IntPoint const& v) { return !v.is_zero(); }, [](OneOf auto const& v) { return !v.is_empty(); }, [](Enum auto const&) { return true; }, - [](OneOf, NonnullRefPtr, GUI::Icon> auto const&) { return true; }); + [](OneOf, NonnullRefPtr, GUI::Icon> auto const&) { return true; }); } i32 as_i32() const { return get(); } @@ -139,6 +140,7 @@ public: return fallback; } + double as_double() const { return get(); } Gfx::IntPoint as_point() const { return get(); } Gfx::IntSize as_size() const { return get(); } Gfx::IntRect as_rect() const { return get(); }