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

SliderInt with reversed range cannot reach min value #3432

Closed
MultiPain opened this issue Aug 25, 2020 · 3 comments
Closed

SliderInt with reversed range cannot reach min value #3432

MultiPain opened this issue Aug 25, 2020 · 3 comments

Comments

@MultiPain
Copy link

MultiPain commented Aug 25, 2020

Version: 1.77
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: Custom engine
Operating System: Windows 10

sizeof(size_t): 4, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201402
define: _WIN32
define: __MINGW32__
define: __GNUC__=7

My Issue/Question:

Hi, im making a lua binding for Gideros mobile game engine and recently I discovered that if min slider value is greater than max then int slider cant reach min value. Ive also added a custom slider, but it 99.99% identical to built-in slider. The difference only in drawing knob :)

Screenshots/Video

sliders_huh
As you can see, slider cant reach 0 for some reason.

static int v = 0;
static float f = 0.0f;

ImGui::SliderInt("int slider", &v, 0, 100);
ImGui::SliderFloat("float slider", &f, 0.0f, 100.0f, "%.0f");

ImGui::PushID(1);
ImGui::SliderInt("int slider", &v, 100, 0);
ImGui::SliderFloat("float slider", &f, 100.0f, 0.0f, "%.0f");
ImGui::PopID();
@ocornut ocornut changed the title SliderInt cant reach min value SliderInt with reversed range cannot reach min value Aug 25, 2020
@MultiPain
Copy link
Author

MultiPain commented Aug 30, 2020

Also, "ImGuiSliderFlags_ClampOnInput" does not work in this situation.
I have fixed it by my own like that:

template<typename T>
static bool DataTypeClampT(T* v, const T* v_min, const T* v_max)
{

    // Clamp, both sides are optional, return true if modified
    if (*v_min < *v_max)
    {
        if (v_min && *v < *v_min) { *v = *v_min; return true; }
        if (v_max && *v > *v_max) { *v = *v_max; return true; }
        return false;
    }
    else
    {
        if (v_min && *v > *v_min) { *v = *v_min; return true; }
        if (v_max && *v < *v_max) { *v = *v_max; return true; }
        return false;
    }
}

ocornut pushed a commit that referenced this issue Sep 7, 2020
…nges, both with signed and unsigned types. Added reverse Sliders to Demo. (#3432, #3449)
@ocornut
Copy link
Owner

ocornut commented Sep 7, 2020

recently I discovered that if min slider value is greater than max then int slider cant reach min value.

Now fixed by @rokups with b2039aa. Note that reverse slider weren't really documented until now (added some examples in demo).

Will be looking at the clamping next.

I have fixed it by my own like that:

 // Clamp, both sides are optional, return true if modified
 if (*v_min < *v_max)
 {

That's a crash if either bounds are disabled.

@ocornut
Copy link
Owner

ocornut commented Sep 7, 2020

Also, "ImGuiSliderFlags_ClampOnInput" does not work in this situation.

This is now fixed by 36af398

@ocornut ocornut closed this as completed Sep 7, 2020
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