浏览代码

LibGUI: Add Variant::as_float_or(fallback)

Andreas Kling 4 年之前
父节点
当前提交
2d1eff01a2
共有 1 个文件被更改,包括 7 次插入0 次删除
  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;
         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
     Gfx::IntPoint as_point() const
     {
     {
         return { m_value.as_point.x, m_value.as_point.y };
         return { m_value.as_point.x, m_value.as_point.y };