summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-09-28 20:04:02 +0200
committerYuri Sizov <yuris@humnom.net>2023-09-28 20:04:02 +0200
commit4f0e2ea86e84e369b249bdcdffec254f28e948e2 (patch)
tree871935f1f631ba4a95d3eb15550b942013a9db4a
parent813cd1dfc8fb7e6b8cfbc6945ecdf550a7f673a2 (diff)
parent4d3dc0e9443d1e21f6e3e3d5755e5a0705b55024 (diff)
downloadredot-engine-4f0e2ea86e84e369b249bdcdffec254f28e948e2.tar.gz
Merge pull request #80699 from aXu-AP/spin-box-comma-decimals
Allow comma as a decimal separator for SpinBox
-rw-r--r--editor/gui/editor_spin_slider.cpp21
-rw-r--r--scene/gui/spin_box.cpp20
2 files changed, 30 insertions, 11 deletions
diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp
index a1b0ecad6b..750837cce9 100644
--- a/editor/gui/editor_spin_slider.cpp
+++ b/editor/gui/editor_spin_slider.cpp
@@ -525,17 +525,24 @@ String EditorSpinSlider::get_suffix() const {
}
void EditorSpinSlider::_evaluate_input_text() {
- // Replace comma with dot to support it as decimal separator (GH-6028).
- // This prevents using functions like `pow()`, but using functions
- // in EditorSpinSlider is a barely known (and barely used) feature.
- // Instead, we'd rather support German/French keyboard layouts out of the box.
- const String text = TS->parse_number(value_input->get_text().replace(",", "."));
-
Ref<Expression> expr;
expr.instantiate();
+
+ // Convert commas ',' to dots '.' for French/German etc. keyboard layouts.
+ String text = value_input->get_text().replace(",", ".");
+ text = text.replace(";", ",");
+ text = TS->parse_number(text);
+
Error err = expr->parse(text);
if (err != OK) {
- return;
+ // If the expression failed try without converting commas to dots - they might have been for parameter separation.
+ text = value_input->get_text();
+ text = TS->parse_number(text);
+
+ err = expr->parse(text);
+ if (err != OK) {
+ return;
+ }
}
Variant v = expr->execute(Array(), nullptr, false, true);
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 07429c6a61..e13fd21949 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -62,12 +62,24 @@ void SpinBox::_text_submitted(const String &p_string) {
Ref<Expression> expr;
expr.instantiate();
- String num = TS->parse_number(p_string);
+ // Convert commas ',' to dots '.' for French/German etc. keyboard layouts.
+ String text = p_string.replace(",", ".");
+ text = text.replace(";", ",");
+ text = TS->parse_number(text);
// Ignore the prefix and suffix in the expression.
- Error err = expr->parse(num.trim_prefix(prefix + " ").trim_suffix(" " + suffix));
+ text = text.trim_prefix(prefix + " ").trim_suffix(" " + suffix);
+
+ Error err = expr->parse(text);
if (err != OK) {
- _update_text();
- return;
+ // If the expression failed try without converting commas to dots - they might have been for parameter separation.
+ text = p_string;
+ text = TS->parse_number(text);
+ text = text.trim_prefix(prefix + " ").trim_suffix(" " + suffix);
+
+ err = expr->parse(text);
+ if (err != OK) {
+ return;
+ }
}
Variant value = expr->execute(Array(), nullptr, false, true);