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

DragFloatRange2 and DragIntRange2 fail to check bounds #1441

Closed
sammalt opened this issue Nov 15, 2017 · 2 comments
Closed

DragFloatRange2 and DragIntRange2 fail to check bounds #1441

sammalt opened this issue Nov 15, 2017 · 2 comments

Comments

@sammalt
Copy link

sammalt commented Nov 15, 2017

There is a bug in both of these, which makes it to not respect the bounds set by v_min and v_max parameters.

Repro

  1. open imgui demo -> widgets -> Range Widgets
  2. drag Min: 10.0 % to 0 %
  3. drag Max: 90.0 % to 0 %
  4. drag Min: 0% left -> boom.

Now Min widget no longer respects the v_min and v_max parameters, you can drag it negative percents (below v_min), over the current max value and over v_max. You can do it also the other way around: drag the min value all the way to v_max, and then the current max no longer respects the bounds.

You can observe the same behavior in DragIntRange2 - but not in the ImGui demo, of course ;)

Edit: version 1.52

@ocornut ocornut added the bug label Nov 15, 2017
@ocornut
Copy link
Owner

ocornut commented Nov 15, 2017

Ouch, this is quite an issue.

It's a little delicate to fix because DragFloat() signature basically says that when v_min==v_max there's no bound. So we'd need to fix that, and probably switch to using -FLT_MAX..FLT_MAX as default values, but it makes DragFloat() less welcoming when you want to fill in the extra parameters (also I wonder if all languages have access to a reliable version of FLT_MAX).

The other solution would be to make that change only in an internal version DragFloatEx() which is wrapped by DragFloat() with a translation of v_min==v_max to -FLT_MAX,FLT_MAX, and then the DragFloatRange2() can use this function directly.

I think I prefer the second solution as it won't break user code, and we can always morph the second solution into the first one later if we want to.

Added reference to #76

@ocornut
Copy link
Owner

ocornut commented Jul 23, 2020

Hello @sammalt,
When exploring old issues I realized that this was now easily fixable with the changes made by 0537ac0.
So this is now fixed.
Thank you.

@ocornut ocornut closed this as completed Jul 23, 2020
Mernion pushed a commit to Mernion/imgui that referenced this issue Aug 3, 2020
…f bounds when both min and max value are on the same value. (ocornut#1441)
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

2 participants