Browse Source

LibGUI: Add double type to Variant

Bastiaan van der Plaat 1 year ago
parent
commit
3acbffabf9
2 changed files with 9 additions and 2 deletions
  1. 5 0
      Userland/Libraries/LibGUI/Variant.cpp
  2. 4 2
      Userland/Libraries/LibGUI/Variant.h

+ 5 - 0
Userland/Libraries/LibGUI/Variant.cpp

@@ -43,6 +43,11 @@ Variant& Variant::operator=(JsonValue const& value)
         return *this;
         return *this;
     }
     }
 
 
+    if (value.is_double()) {
+        set(value.as_double());
+        return *this;
+    }
+
     if (value.is_string()) {
     if (value.is_string()) {
         set(value.as_string());
         set(value.as_string());
         return *this;
         return *this;

+ 4 - 2
Userland/Libraries/LibGUI/Variant.h

@@ -21,7 +21,7 @@ namespace Detail {
 struct Boolean {
 struct Boolean {
     bool value;
     bool value;
 };
 };
-using VariantUnderlyingType = AK::Variant<Empty, Boolean, float, i32, i64, u32, u64, DeprecatedString, Color, Gfx::IntPoint, Gfx::IntSize, Gfx::IntRect, Gfx::TextAlignment, Gfx::ColorRole, Gfx::AlignmentRole, Gfx::FlagRole, Gfx::MetricRole, Gfx::PathRole, NonnullRefPtr<Gfx::Bitmap const>, NonnullRefPtr<Gfx::Font const>, GUI::Icon>;
+using VariantUnderlyingType = AK::Variant<Empty, Boolean, float, double, i32, i64, u32, u64, DeprecatedString, Color, Gfx::IntPoint, Gfx::IntSize, Gfx::IntRect, Gfx::TextAlignment, Gfx::ColorRole, Gfx::AlignmentRole, Gfx::FlagRole, Gfx::MetricRole, Gfx::PathRole, NonnullRefPtr<Gfx::Bitmap const>, NonnullRefPtr<Gfx::Font const>, GUI::Icon>;
 }
 }
 
 
 class Variant : public Detail::VariantUnderlyingType {
 class Variant : public Detail::VariantUnderlyingType {
@@ -76,6 +76,7 @@ public:
     bool is_u32() const { return has<u32>(); }
     bool is_u32() const { return has<u32>(); }
     bool is_u64() const { return has<u64>(); }
     bool is_u64() const { return has<u64>(); }
     bool is_float() const { return has<float>(); }
     bool is_float() const { return has<float>(); }
+    bool is_double() const { return has<double>(); }
     bool is_string() const { return has<DeprecatedString>(); }
     bool is_string() const { return has<DeprecatedString>(); }
     bool is_bitmap() const { return has<NonnullRefPtr<Gfx::Bitmap const>>(); }
     bool is_bitmap() const { return has<NonnullRefPtr<Gfx::Bitmap const>>(); }
     bool is_color() const { return has<Color>(); }
     bool is_color() const { return has<Color>(); }
@@ -102,7 +103,7 @@ public:
             [](Gfx::IntPoint const& v) { return !v.is_zero(); },
             [](Gfx::IntPoint const& v) { return !v.is_zero(); },
             [](OneOf<Gfx::IntRect, Gfx::IntSize> auto const& v) { return !v.is_empty(); },
             [](OneOf<Gfx::IntRect, Gfx::IntSize> auto const& v) { return !v.is_empty(); },
             [](Enum auto const&) { return true; },
             [](Enum auto const&) { return true; },
-            [](OneOf<float, DeprecatedString, Color, NonnullRefPtr<Gfx::Font const>, NonnullRefPtr<Gfx::Bitmap const>, GUI::Icon> auto const&) { return true; });
+            [](OneOf<float, double, DeprecatedString, Color, NonnullRefPtr<Gfx::Font const>, NonnullRefPtr<Gfx::Bitmap const>, GUI::Icon> auto const&) { return true; });
     }
     }
 
 
     i32 as_i32() const { return get<i32>(); }
     i32 as_i32() const { return get<i32>(); }
@@ -139,6 +140,7 @@ public:
         return fallback;
         return fallback;
     }
     }
 
 
+    double as_double() const { return get<double>(); }
     Gfx::IntPoint as_point() const { return get<Gfx::IntPoint>(); }
     Gfx::IntPoint as_point() const { return get<Gfx::IntPoint>(); }
     Gfx::IntSize as_size() const { return get<Gfx::IntSize>(); }
     Gfx::IntSize as_size() const { return get<Gfx::IntSize>(); }
     Gfx::IntRect as_rect() const { return get<Gfx::IntRect>(); }
     Gfx::IntRect as_rect() const { return get<Gfx::IntRect>(); }