Giter Site home page Giter Site logo

Comments (6)

the-marenga avatar the-marenga commented on August 18, 2024

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

from iced_aw.

genusistimelord avatar genusistimelord commented on August 18, 2024

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.

from iced_aw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.