-
-
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
SliderFloat clamping to zero too aggressively with logarithms #642
Comments
There is also a problem with the minimum value that I pass in not being all the way on the left side of the slider. If you try the code below, you will notice that the minimum value is in the middle of the slider instead of on the left. The maximum value is correctly located on the right though.
|
It makes sense for many use cases! It's nice to have those rounded values and not always get "1.2673476" every time one click on a typical slicker. And we actually have display matching the real value. Adding extra parameters to those functions not really trivial (API explosion issue). So while I agree that we should allow to disable that clamping I haven't yet figured out what is the best path toward making it happen. Probably need to play a little more with that sort of range too. The later (second message) is very definitively a bug. Should look into it. This is closely related to your other issue #643 that the internal of those functions probably need a reoverhaul. |
I understand the problem now. You are doing the clamp because you want the value that is stored in the float to match what is displayed on the screen. I was thinking it was to avoid the issue that The most general, easiest way to get the behavior you want is probably not to create your own parsing code to find As a proof of concept, I routed the format string through
I noticed you had a comment. |
That, and if you are authoring data interactively (say: level designer or game designer tweaking stuff) and those data are meant to be seen by developers, it is just nicer to have round number like 0.001f and not float with lots of significant digits everywhere, when that precision isn't required. So the user can explicitly request more precision if they want it. FYI other less obvious but very useful use of those format strings include:
Mentioning those because we probably need to have the full scope in mind if changing this code. |
I am not sure this is a bug per se. ^10 curve is very flat in small number before going very steep. With 3 decimals of precision it takes moving to the right for a big portion of that range until we hit a value that is bigger >= 0.101f. You can either increase the precision or reduce the power curve steepness. |
In my view, not having the ends of the slider map to the min and max values in the specified input range is a bug. You can argue that the impact of the bug is minimal and not worth addressing (maybe that is what you mean by an enhancement). It is a valid point that this is unlikely to affect most users. I made a contrived example to make the problem easily reproducible, but I originally noticed the problem as a hitch at the bottom range of the slider with a much smaller minimum value. I don't see how using a |
Now that I think about it, I guess this isn't a logarithmic slider, because a log is a log is a log. The spacing shouldn't change based on power. I don't know what the slider is doing or maybe I'm confusing myself. Anyhow, the ends not matching up is weird. Is there a logarithmic slider in ImGui that I didn't notice? I just assumed that was what the power parameter affected. A log is what I really want. :-) |
If you plot x^10 from 0 to 1, about half on the left side would be below 0.101. I'm not sure what you mean exactly by logarithmic slider here. Not acting dumb but everybody may have a slightly different perception at how non-linear sliders may work. The behavior I'm using for SliderFloat() may be totally inadequate! I haven't used scientific/maths apps so I may be totally off your habits. You can play with simpler range and powers (like 2.0f) to have a feel for it.
At 50% of the slider we are at 1 The SliderBehavior code for positive values/ranges does: (some unrelated code omited)
It may be odd to counter-intuitive for you. I am not against changing it. |
I've spent a while trying to get my mind around the
Note that 1.0 is precisely in the middle because
The current slider implementation seems to be polynomial with EDIT: Scaling is done by |
@AndrewBelt As stated above I don't mind changing that. That code is something I stupidly grabbed from another piece of code I wrote in 2009 and I didn't give it much though back then. Also, please, nobody should trust me on anything related to maths :) |
Working on one! (See my edit if you missed it) |
@AndrewBelt As per your PR and comment above: I don't think backward compatibility is most important there as long as we explain the change. What would be your preferred design/api if backward compatibility was ignored? |
Existing:
Proposed:
To clean up the code, the |
Do you think base-e natural logarithm is the only base that would be useful? How would |
The beautiful thing about logarithms is that a change of base means a simple rescaling
since the Boolean arguments are indeed controversial, but the recommended alternative is always a new function with a different name suggesting its different behavior. Following that logic, there should be a SliderFloatLog function, but since that would be extremely redundant code, you would want to implement internally it with a boolean argument in SliderFloat anyway and call SliderFloat(..., true) from the new hypothetical SliderFloatLog function. If you want to keep power != 1.0, you could call the existing nonlinear scaling "polynomial" or "power" scaling because maybe |
DragFloat is possible, I'll look at that. Instead of adding some delta_v to the value, you'd multiply it by some number, like |
I think (It will probably end up being exposed as a SliderFlags_XXX in the future, it's just that I cannot think of much Slider flags for now so it's weird exposing it. At minimum, I envision that in the future we'll have Slider variations, with a configurable default, and an style/behavior override through the flags.) I'll ask around to people who may have been using that power parameter. Don't worry about the API side in the PR for now (I can always merge and rework it). Thanks! |
Thinking about it a bit more, it might be best to keep the old API and improve the I realized that there are 9 or 10 widgets that use |
A workaround for those wanting logarithmic input is to sprintf a current value into a string to pass it to the format, then take the log of the value, set the slider range to the log of the desired min and max, then take the exponential of the result.
|
Hello, (repost with missing contents) EDIT Removed suggestion that rounding to format has been fixed/removed: it has NOT but we are not able to add the option trivially. In fact I just did! See aad61cb. Currently reopening that dangling topic since we've working on variety of related changes (see #3361) Quoting Ben: _"I've pushed some experiments in logarithmic slider behaviour to features/logarithmic_sliders. I haven't done any API refactoring work yet - this is purely about the maths so far, and trying to take the basic concept of #1316 and make it usable for a range of cases (since that PR as-is I felt like has way too many user-facing non-obvious gotchas/bugs - any range where zero or negative numbers was involved would break in weird ways, for example, as would "backwards" ranges). [...] "The log() stuff in #1316 is fine as long as the range doesn't cross 0, IIRC, but inherently logarithmic stuff kinda blows up at zero so to work with sliders that do (e.g.) -100 to 100 as their range the code has to split that into two logarithmic ranges and handle them separately. Also, ranges to go down to zero without crossing it also need careful clamping to avoid the clamp making the log behaviour blow up (not "blow up" mathematically, as such, but generate unhelpful things like a 0-10 range slider where 95% of the slider pixels are dedicated to the 0-0.01 part of the range)." |
This is now fixed, added explicit _Logarithmic flags and _NoRoundToFormat flags to decorrelate rounding underlying value from formatted value. See #3361 for details. |
I ran into a problem with the logarithmic slider. I am trying to control some weighting parameters that can be very small. I display in scientific format with only a few decimal places (for example "%.3g"), but need to support values in the range 1e-9 to 1, for example. The current behavior clamps the slider to the precision of the format string, which causes a huge jump at low values. Basically, there is a connection between display format and clamping currently that doesn't make much sense to me.
I got rid of the rounding by commenting out the line shown below in ImGui::SliderBehavior. I'm only taking logs of positive numbers, so I don't need clamping (min value is sufficient). You clearly want support negative numbers also, so a more general solution would maybe be to only allow clamping for non-logarithmic sliders? Maybe pass the clamp value as a separate parameter from the display format?
The text was updated successfully, but these errors were encountered: