Skip to content
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

number_input, unable to type non-integer numbers. #234

Open
David-Aguilo opened this issue Apr 26, 2024 · 4 comments
Open

number_input, unable to type non-integer numbers. #234

David-Aguilo opened this issue Apr 26, 2024 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@David-Aguilo
Copy link

Good afternoon.
With the number_input, I am unable to type non-integer numbers. On the example provided for use of the widget, I can obtain 10.5 for example if I press the arrow up or scroll.
2024-04-26-155931_grim

However, if I try to type it, I am unable to.
2024-04-26-155925_grim

I think the cause is that the dot is parsed and removed before I can type what goes after it. Furthermore, I can also input a non-integer number if I type it elsewhere and copy and paste it into the application.

I don't know wether I have to enable a setting I am unaware of or if this is unimplemented functionality.

Thank you for everything.
Kind regards.

@genusistimelord genusistimelord added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Apr 26, 2024
@the-marenga
Copy link
Contributor

I tried to do this, when I reworked a few number_input things some time ago and there is one edge case I could not solve.

The problem becomes appending a dot, because the current value always has to be a valid number. Let say the current number is 10, we can change it to .10, which is valid (0.1) and 1.0, which is valid, but 10. would not be valid, which means nothing happens. You can solve that by artificially appending a 0 to make it 10.0 and use that value, but we have a similar problem here. The string 10.0 is the same float, as the old 10, so even though a on_changed is triggered and a message is emmited, the actual float does not change and thus will be rendered/formated as just "10" again, which means from a users perspective, the dot input was ignored. This is especially bad since this appending case is probably the most likely case for normal user input (writing a number left to right).

I only realy see two ways to make this work here.

  1. Ignore appending dots and just work with the inputting dots in the middle and at the beginning
  2. Force floats to always be formated with at least one decimal place (10.0), at which point inputting dots would becomes pointless

If either of them seem like a useable solution for the time being, I could add them, but I feel like they are both not great, which is why I gave up this initially

In theory there might be a 3. option involving decoupeling the text_input state&on_changed from the number_inputs, but that seems like a hard and error prone thing do do

@genusistimelord
Copy link
Collaborator

yeah the issue here is ignore or not. I think not ignoring might be better since on the visual side we can make it appear as with just the dot but on the numeric side we can append a .0. This generally will be better for floating point numbers. as auto placing it on the string can mess up someones typing of a number if they have not finished yet. the only other way would be to make it focused and when enter is hit to make it unfocused then to do the .0 addition and such and not check the number till then. Downside to this is you need to handle the max and min by manually clamping the number after parsing it and then changing the string to what fits.

@Redhawk18
Copy link
Contributor

Do negative numbers work? I'm unsure if your able to parse the -

@genusistimelord
Copy link
Collaborator

genusistimelord commented May 14, 2024

  • does work im just unsure if you can type it or not. The other issue is knowing if it is a float or not. I guess ill need to see if number traits has something to tell us.

I guess we can always do

  if TypeId::of::<T>() == TypeId::of::<String>() {
        println!("string={:?}", val)
    } else {
        println!("value={:?}", val)
    }
to know if it is a float or not to allow usage of . and even - in typing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants