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

Bug with clamping values in DragScalar if limits the same #7968

Closed
wants to merge 2 commits into from

Conversation

DimaKoltun
Copy link
Contributor

float minValue = -180.0f;
float maxValue = 1.0f;

{
    ImGui::Begin("Test DragScalar");

    ImGui::DragFloat("Min Limit", &minValue, 1.0f, -180.0f, maxValue, "%.3f", ImGuiSliderFlags_AlwaysClamp);
    ImGui::DragFloat("Max Limit", &maxValue, 1.0f, minValue, 180.0f, "%.3f", ImGuiSliderFlags_AlwaysClamp);

    ImGui::End();
}

If you change "Max Limit" to -180 then you can make "Min Limit" lower than -180, so PR fix this problem

@ocornut
Copy link
Owner

ocornut commented Oct 3, 2024

Unfortunately this would also pretty much break the basic assumption of DragXXX functions:
Use v_min < v_max to clamp edits to given limits
Where default values are v_min = v_max = 0.0f.

However, since last time this has been discussed we now have flags available in the API, I think we can add one to specify always using those values.

@ocornut
Copy link
Owner

ocornut commented Oct 3, 2024

(Please note that the current workaround is to use ImGuiSliderFlags_ReadOnly or ImGuiItemFlags_ReadOnly for now. But I aim to fix this better)

ocornut added a commit that referenced this pull request Oct 3, 2024
@ocornut
Copy link
Owner

ocornut commented Oct 3, 2024

I have pushed b3c8747 which introduces:

  • Added ImGuiSliderFlags_ClampZeroRange
  • Added ImGuiSliderFlags_ClampOnInput (old behavior of _AlwaysClamp)
  • Changed ImGuiSliderFlags_AlwaysClamp to = ImGuiSliderFlags_ClampOnInput | ImGuiSliderFlags_ClampZeroRange

I have changed default logic to assume clamping when v_min==v_max with values != 0.0f
For values == 0.0f, ImGuiSliderFlags_ClampZeroRange is required due to legacy reason.

@ocornut ocornut closed this Oct 3, 2024
ocornut added a commit to ocornut/imgui_test_engine that referenced this pull request Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants