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

Double precision support #1011

Closed
lycium opened this issue Feb 8, 2017 · 6 comments
Closed

Double precision support #1011

lycium opened this issue Feb 8, 2017 · 6 comments

Comments

@lycium
Copy link

lycium commented Feb 8, 2017

Sorry if this has been mentioned before (seems quite an obvious request, though I couldn't find any mention of it), but would it be possible to support double precision as well? For example, in addition to:

bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)

there would also be:

bool ImGui::SliderDouble(const char* label, double* v, double v_min, double v_max, const char* display_format, double power)

I'm aware that it could potentially lead to lots of code duplication, though maybe this can be avoided by templating the code. On the other hand, without double precision support in imgui, it becomes extremely awkward to edit our double precision internal data / very frustrating to work around.

I'm also aware that games typically don't use much double precision, but sometimes they might, and for other applications it can also be useful.

It's pretty easy to hack up this support myself and submit the pull request, but I'm first curious to know if it would be considered at all.

Thanks for your awesome library!

@lycium
Copy link
Author

lycium commented Feb 14, 2017

I've found this previous issue now after searching more deeply: #320

Apparently the preferred way to handle this is via string processing on the inputs, but that opens a whole can of worms (validation, fast and accurate string <=> double conversion, ...) and generally breaks the main nice thing about ImGui, that you can just drop it in to make your data editable.

@ocornut
Copy link
Owner

ocornut commented Feb 14, 2017

I'd like to solve this problem eventually. As you pointed out one of the problem is the explosion of API entry points.

Apparently the preferred way to handle this is via string processing on the inputs, but that opens a whole can of worms (validation, fast and accurate string <=> double conversion, ...) and generally breaks the main nice thing about ImGui, that you can just drop it in to make your data editable.

Creating an InputDouble function in your code (within ImGui namespace) that uses sprintf+InputText+sscanf should be fairly easy and only a few lines of code.

@IsaacWoods
Copy link

IsaacWoods commented Aug 17, 2017

This seems like a common enough thing to want to do to justify adding to ImGui proper. Through either templating or just creating those functions, it would be nice to see this. Our entire codebase uses double and it would be nice to use some of the more advanced widgets.

ocornut added a commit that referenced this issue Mar 22, 2018
…arsScientific to add 'e' 'E' to list of characters that can be input. (later useful for #1011)
ocornut added a commit that referenced this issue Mar 22, 2018
…imal_precision parameter to also for "%e" and variants. (#1011) May transition the other InputXXX function to use format strings as well.
@ocornut
Copy link
Owner

ocornut commented Apr 3, 2018

@lycium, @IsaacWoods Sorry I didn't get to react earlier and with more details on this.

  1. I have added a InputDouble() function recently.

  2. As you pointed out, we will probably end up something sort sort of generic mechanism internally to make it easier to expose more function, so I still plan to add the SliderFloat, DragFloat functions at some point. Will work on making that possible, as there's a little more work involved for slider and drag as they are designed around float (even the int path uses float, which is occasionally problematic).

@lycium
Copy link
Author

lycium commented Apr 3, 2018

That's awesome, thank you!

ocornut added a commit that referenced this issue Apr 27, 2018
…n Ctrl+Clicking a slider or drag, matching the change done in c19b278 for InputFloat().  (#648, #1011)
ocornut added a commit that referenced this issue May 3, 2018
…putScalar(). Removed internal.h InputScalarEx() to InputScalar(). Removed cheap-relative-operators support in recently added U32 data path, since this is heading toward being legacy code. + Fixed InputDouble parsing code. (#1011, #320, #708)
ocornut added a commit that referenced this issue May 3, 2018
…tor and no absolute values so we will be able to manipulate double as well as 64-bit integers. (#1011, #708, #320)
ocornut added a commit that referenced this issue May 3, 2018
ocornut added a commit that referenced this issue May 3, 2018
…ScalarN(), removed InputFloatN(), InputInt(). Note that DragInt2/3/4 will %f format strings will currently be broken. (#320, #643, #708, #1011)
ocornut added a commit that referenced this issue May 3, 2018
ocornut added a commit that referenced this issue May 4, 2018
…h various ranges/limits. Note that Drag/Slider/Input currently fail if the format string doesn't preview the actual value. Will fix next. (#320, #643, #708, #1011)
@ocornut
Copy link
Owner

ocornut commented May 4, 2018

FYI, I have added functions in a branch to work with float, double, 32/64 bits, signed and unsigned (and in a proper lossless manner, as previously some functions didn't work great with big integers).
See #643 for details.

@ocornut ocornut closed this as completed May 4, 2018
ocornut added a commit that referenced this issue Feb 27, 2019
…6 data types. We are reusing function instances for larger types to reduce code size. (#643, #320, #708, #1011)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants