-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow comma as a decimal separator for SpinBox #80699
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally (rebased on top of master
a278c1b), it works as expected.
I have an implementation in #80541 which I think is better, even if a bit overkill. This implementation just checks for |
Oh, I didn't see that! Good work. I just came up with a third option, which is elegant and handles even edge cases: What if we tried parsing the text and if parse fails then try replacing commas and reparse? I'm testing this rn (ie. waiting to build 😴). |
It seems that expression succeeds even if there is some commas just lying around - the rest just gets cut off (eg. Oh well, I think this is good enough, or use Mew's fancier version if you want to handle more cases 😀 |
Awh, the idea sounded very good in practice. Maybe there's some way to find whether Expression needs to do some meddling to make the string valid, so after two fails it trims off the "invalid part"? I don't know if the functionality exists in practice |
1826b1a
to
16a301a
Compare
It worked out in the end! I just needed to try first converting commas, then in case of failure parse again without conversion. Now I couldn't find any edge cases, seems to work in all (sensible) cases. |
Yay! This supersedes my PR beautifully then |
Add support for comma ',' as a decimal separator for SpinBox. This implementation allows for expressions like `pow(2, 3)` to be used as well. If you use comma to separate decimals, use semicolon `;` to separate function parameters. Change EditorSpinSlider behavior to match.
16a301a
to
4d3dc0e
Compare
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine, but seeing the duplicate code in EditorSpinSlider and SpinBox I wonder if maybe it should be a static SpinBox method, with text as a parameter?
Thanks! |
This problem came back in Godot 4.3 :/ |
Can you elaborate? For me it seems to be working both in 4.3 and in master. |
Fixes #80664
Add support for comma
,
as a decimal separator for SpinBox. This implementation allows for expressions likepow(2, 3)
to be used as well. If you use comma to separate decimals, use semicolon;
to separate function parameters.Change EditorSpinSlider behavior to match (currently EditorSpinSlider accepts commas but not expression with multiple parameters).
Caveats:
As comma replacing is triggered only in absence of parentheses, there's some cases where replacing doesn't trigger even if it would still make sense for exampleNewer version handles these cases too.(1 + 0,5) * 2
. However, if user needs to write something more complex than what can be inputted via numpad they probably don't mind using dot for decimals.This is also a change to an existing Control, but I can't see anybody relying on input failing whenever commas are present.
Bugsquad edit: Fixes #81989