From 5737a79c8dffb8c20f6b23f6f28b01318be08483 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 22 Mar 2015 15:58:44 +0000 Subject: [PATCH] Fixed new window from having an incorrect content size on their first frame (#175) --- imgui.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 1337caab..ced05423 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2898,9 +2898,13 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg IM_ASSERT(name != NULL); // Must pass a name // Find or create + bool window_is_new = false; ImGuiWindow* window = FindWindowByName(name); if (!window) + { window = CreateNewWindow(name, size, flags); + window_is_new = true; + } window->Flags = (ImGuiWindowFlags)flags; // Add to stack @@ -2967,7 +2971,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg window->ClipRectStack.resize(0); // Reset contents size for auto-fitting - window->SizeContents = window->DC.CursorMaxPos - window->Pos; + window->SizeContents = window_is_new ? ImVec2(0.0f, 0.0f) : window->DC.CursorMaxPos - window->Pos; window->SizeContents.y += window->ScrollY; if (flags & ImGuiWindowFlags_ChildWindow)