Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Setting size constraints to a non-integer value can make the window move by itself (as in #2067) #2530

Closed
przemkovv opened this issue May 3, 2019 · 3 comments

Comments

@przemkovv
Copy link

przemkovv commented May 3, 2019

Version/Branch of Dear ImGui:

Version: 1.69

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp + imgui_impl_win32.cpp
Operating System: Windows

My Issue/Question:

I encountered the same issue as described in #2067, however, it is caused by non-rounded values of SizeConstraintRect . In that case, the CalcSizeAfterConstraint function returns a new, non-rounded size which is then used by a code fragment quoted in #2067.

static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size) 
{
    // ....
    // g.NextWindowData.SizeConstraintRect = {Min={x=475.200012 y=0.000000000 } Max={x=475.200012 y=688.799988 } }
    // new_size = {x=475.000000 y=491.000000 }

    ImRect cr = g.NextWindowData.SizeConstraintRect;
    new_size.x = (cr.Min.x >= 0 && cr.Max.x >= 0) ? ImClamp(new_size.x, cr.Min.x, cr.Max.x) : window->SizeFull.x;
    new_size.y = (cr.Min.y >= 0 && cr.Max.y >= 0) ? ImClamp(new_size.y, cr.Min.y, cr.Max.y) : window->SizeFull.y;

    // new_size = {x=475.200012 y=491.000000 }
    // ....
}

Standalone, minimal, complete and verifiable example:
Add this:

        ImGui::SetNextWindowPos(ImVec2{ 901.0f, 103.0f }, ImGuiCond_Once);

        ImGui::SetNextWindowSizeConstraints({ 475.200012f, 100.0f }, { 475.2000123f, 100.4f });
        ImGui::Begin("Test");
        ImGui::End();

to any of examples.

@ocornut
Copy link
Owner

ocornut commented May 3, 2019

Hello,
Could you provide a simple repro? Thank you.

@przemkovv
Copy link
Author

Sorry, I've edited the first message. It is enough to put the snippet in any of your examples.

Thank you!

ocornut added a commit that referenced this issue May 3, 2019
@ocornut
Copy link
Owner

ocornut commented May 3, 2019

Thank you! Pushed the fix now!

Here's the test for it (also added a test for #2067)

t = REGISTER_TEST("window", "window_size_unrounded");
t->GuiFunc = [](ImGuiTestContext* ctx)
{
    // Test that non-rounded size constraint are not altering pos/size (#2530)
    ImGui::SetNextWindowPos(ImVec2(901.0f, 103.0f), ImGuiCond_Once);
    ImGui::SetNextWindowSize(ImVec2(348.48f, 400.0f), ImGuiCond_Once);
    ImGui::SetNextWindowSizeConstraints(ImVec2(475.200012f, 0.0f), ImVec2(475.200012f, 100.4f));
    ImGui::Begin("Issue 2530", NULL, ImGuiWindowFlags_NoSavedSettings);
    ImVec2 pos = ImGui::GetWindowPos();
    ImVec2 size = ImGui::GetWindowSize();
    IM_CHECK(pos.x == 901.0f && pos.y == 103.0f);
    IM_CHECK(size.x == 475.0f && size.y == 100.0f);
    ImGui::End();
}

@ocornut ocornut closed this as completed May 3, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants