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

Fixed auto-resize collapse bug introduced by d9a84de #2336

Closed
wants to merge 1 commit into from
Closed

Fixed auto-resize collapse bug introduced by d9a84de #2336

wants to merge 1 commit into from

Conversation

luney112
Copy link

@luney112 luney112 commented Feb 8, 2019

Hi,

This PR addresses the re-introduction of the bug described in #176 caused by d9a84de.

capture

The fix: Only use the SizeContents value if it's collapsed and the auto-resize flag is NOT set. Otherwise, it will not calculate the content size properly.

@ocornut
Copy link
Owner

ocornut commented Feb 8, 2019

I think there is a more general issue here that is unrelated to Auto-resizing window.
This for example leads to a MinSize window:

ImGui::SetNextWindowCollapsed(true, ImGuiCond_Once);
ImGui::Begin("Issue 2336", NULL, ImGuiWindowFlags_NoSavedSettings);
ImGui::Text("This is some text");
ImGui::Text("This is some more text");
ImGui::Text("This is some more text again");
ImGui::End();

So your PR wouldn't address the general case.
(Looking into it)

@ocornut ocornut added the bug label Feb 8, 2019
ocornut added a commit that referenced this pull request Feb 8, 2019
@ocornut
Copy link
Owner

ocornut commented Feb 8, 2019

Should be fixed now, both for auto-resizing and non-auto-resizing window.
Thanks for the head up and finding this!

Added a test for it.

// Test that a window starting collapsed performs width/contents size measurement on its first few frames.
t = REGISTER_TEST("window", "window_size_collapsed_1");
t->GuiFunc = [](ImGuiTestContext* ctx)
{
    ImGui::SetNextWindowCollapsed(true, ImGuiCond_Once);
    ImGui::Begin("Issue 2336", NULL, ImGuiWindowFlags_NoSavedSettings);
    ImGui::Text("This is some text");
    ImGui::Text("This is some more text");
    ImGui::Text("This is some more text again");

    float w = ImGui::GetWindowWidth();
    if (ctx->FrameCount == 0) // We are past the warm-up frames already
    {
        float expected_w = ImGui::CalcTextSize("This is some more text again").x + ImGui::GetStyle().WindowPadding.x * 2.0f;
        IM_CHECK(ImFabs(w - expected_w) < 1.0f);
    }

    ImGui::End();
};`

@ocornut ocornut closed this Feb 8, 2019
@luney112
Copy link
Author

luney112 commented Feb 8, 2019

Sweet, thanks for taking a look (and the fix!)

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