diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2019-08-29 23:48:50 +0200 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2019-08-29 23:50:56 +0200 |
commit | 86a31e9e385c7909a0cdd24a5ee790c3dca03b98 (patch) | |
tree | d9533da185c7bdedafc6a11a209e8d35db01c3d6 | |
parent | a5e0aa32d9143b115b81788f504fb5bf1a27892a (diff) |
Calculate the SpinBox value using the Expression class
This closes #31780.
-rw-r--r-- | scene/gui/spin_box.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 6ada0cba97..3c63f6b2c7 100644 --- a/scene/gui/spin_box.cpp +++ b/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() { |