You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 19:41:11 +00:00
Merge pull request #80699 from aXu-AP/spin-box-comma-decimals
Allow comma as a decimal separator for SpinBox
This commit is contained in:
@@ -525,17 +525,24 @@ String EditorSpinSlider::get_suffix() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorSpinSlider::_evaluate_input_text() {
|
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;
|
Ref<Expression> expr;
|
||||||
expr.instantiate();
|
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);
|
Error err = expr->parse(text);
|
||||||
if (err != OK) {
|
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);
|
Variant v = expr->execute(Array(), nullptr, false, true);
|
||||||
|
|||||||
@@ -62,12 +62,24 @@ void SpinBox::_text_submitted(const String &p_string) {
|
|||||||
Ref<Expression> expr;
|
Ref<Expression> expr;
|
||||||
expr.instantiate();
|
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.
|
// 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) {
|
if (err != OK) {
|
||||||
_update_text();
|
// If the expression failed try without converting commas to dots - they might have been for parameter separation.
|
||||||
return;
|
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);
|
Variant value = expr->execute(Array(), nullptr, false, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user