浏览代码

Merge pull request #31781 from Calinou/spinbox-use-expressions

Calculate the SpinBox value using the Expression class
Rémi Verschelde 6 年之前
父节点
当前提交
8d78c43ce9
共有 1 个文件被更改,包括 12 次插入8 次删除
  1. 12 8
      scene/gui/spin_box.cpp

+ 12 - 8
scene/gui/spin_box.cpp

@@ -29,6 +29,7 @@
 /*************************************************************************/
 
 #include "spin_box.h"
+#include "core/math/expression.h"
 #include "core/os/input.h"
 
 Size2 SpinBox::get_minimum_size() const {
@@ -50,15 +51,18 @@ void SpinBox::_value_changed(double) {
 
 void SpinBox::_text_entered(const String &p_string) {
 
-	/*
-	if (!p_string.is_numeric())
+	Ref<Expression> expr;
+	expr.instance();
+	Error err = expr->parse(p_string);
+	if (err != OK) {
 		return;
-	*/
-	String value = p_string;
-	if (prefix != "" && p_string.begins_with(prefix))
-		value = p_string.substr(prefix.length(), p_string.length() - prefix.length());
-	set_value(value.to_double());
-	_value_changed(0);
+	}
+
+	Variant value = expr->execute(Array(), NULL, false);
+	if (value.get_type() != Variant::NIL) {
+		set_value(value);
+		_value_changed(0);
+	}
 }
 
 LineEdit *SpinBox::get_line_edit() {