-
-
Notifications
You must be signed in to change notification settings - Fork 10.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
Drag/Slider clamping Min and Max value when using CTRL+Click #1829
Comments
For now all you can do is test the return value of SliderFloat() and clamp your value again when it returns true, if your underlying code really needs the value to be clamped.
|
Testing return values is rather finicky, because the old value will remain in the text input and SliderFloat() will return true in the next frame too (indicating that the value has changed, when in fact it has not). So any code that must perform a special action every time the value is changed needs to have an extra variable to keep track of the "true" value. This is incredibly annoying. The natural expected behavior for a clamped slider is to simply never set the data out-of-bounds. However, imgui.h contains the comment "Manually input values aren't clamped and can go off-bounds." This almost seems like it's advertising a quasi-feature, and I bet some users are relying on the current behavior. If we do decide to clamp keyboard inputs, it seems the easiest way would be to modify both TempInputScalar and DataTypeApplyOpFromText (in imgui_widgets.cpp) to accept min and max parameters, and to clamp the value inside the "expression evaluator" DataTypeApplyOpFromText. But it's probably not the right time because the expression evaluator wants to be rewritten. Still, I'll be happy to make the change if you don't object! Edit: I just found Issue 946, which explains that the current behavior is as intended. |
Resurrecting this old discussion (will copy this comment to #3209 as well)
You can easily wrap that behavior:
If you display a color square to "verify" that the return value is correct when out of bound (doesn't return true every frame):
I've also made internal changes to
And TempInputScalar() now has the following comment:
The only thing missing would be to find a nice way to expose new flags to the Slider/Drag api, being considerate of other desirable features that those function wants (#701), so then we can expose clamping behavior in the function signature. I think the |
This is now supported with |
FYI renamed |
Hello,
So..., how i can limits a value of slider when i use keyboard input ?.
Example:
ImGui::SliderFloat( label, *&value, 1, 10 );
min = 1, max = 10
but if i type by keyboard 100, it will change the variable to 100, even the maximum value being 10.
The text was updated successfully, but these errors were encountered: