Browse Source

LibGUI: Add Variant::as_float_or(fallback)

Andreas Kling 4 years ago
parent
commit
2d1eff01a2
1 changed files with 7 additions and 0 deletions
  1. 7 0
      Userland/Libraries/LibGUI/Variant.h

+ 7 - 0
Userland/Libraries/LibGUI/Variant.h

@@ -175,6 +175,13 @@ public:
         return m_value.as_float;
     }
 
+    float as_float_or(float fallback) const
+    {
+        if (is_float())
+            return as_float();
+        return fallback;
+    }
+
     Gfx::IntPoint as_point() const
     {
         return { m_value.as_point.x, m_value.as_point.y };