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

Keyboard Slider Float Tweaks Not Working With Small Range And %.0f Format #1866

Closed
DomGries opened this issue Jun 7, 2018 · 2 comments
Closed

Comments

@DomGries
Copy link
Contributor

DomGries commented Jun 7, 2018

Expected:
Slider should change value when activating slider keyboard input and using arrow keys

Current:
Slider does not change value when activating slider keyboard input and using arrow keys with small range and format being "%.0f"

Reproduce:

float fieldOfView;
ImGui::SliderFloat("fov", &fieldOfView, 80.f, 120.f, "%.0f");

Details:
There is code in ImGui::SliderBehaviorT like delta /= 100.0f; // Gamepad/keyboard tweak speeds in % of slider bounds which results in step size smaller than 1 with small range and format being "%.0f"

My workaround has been to use ImGui::SliderInt and casting the values between float and int

@ocornut
Copy link
Owner

ocornut commented Jun 7, 2018

Note that holding the arrow keys would work, the float is being modified but there's not enough precision to see it. Near that code I think we should change in SliderBehaviorT:

if (is_decimal || is_power)

With

const int decimal_precision = is_decimal ? ImParseFormatPrecision(format, 3) : 0;
if ((decimal_precision > 0) || is_power)

To match the old behavior. I'll have to think what other side effect it may have.

@ocornut
Copy link
Owner

ocornut commented Jun 7, 2018

Fixed.

@ocornut ocornut closed this as completed Jun 7, 2018
ocornut added a commit that referenced this issue Jun 7, 2018
…t string (e.g. "%.0f"), always step in integer units. (#1866)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants