From 1848480798463e1757bf714fdbcc5de0edf370d7 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 19 Oct 2020 14:06:14 +0200 Subject: [PATCH] Begin: WIP consistent Begin/End behavior, more fixes. --- imgui.cpp | 27 ++++++++++++++------------- imgui_demo.cpp | 15 +++++++-------- imgui_widgets.cpp | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a818748b..1ffd0e5b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4115,7 +4115,9 @@ void ImGui::NewFrame() // - The fallback window exceptionally doesn't call End() automatically if Begin() returns false (this is intended). g.WithinFrameScopeWithImplicitWindow = true; SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver); - Begin("Debug##Default"); + bool ret = Begin("Debug##Default"); + IM_UNUSED(ret); + IM_ASSERT(ret); IM_ASSERT(g.CurrentWindow->IsFallbackWindow == true); // [DEBUG] When io.ConfigDebugBeginReturnValue is set, we make Begin() return false at different level of the window stack to validate Begin()/End() behavior in user code. @@ -5215,7 +5217,6 @@ void ImGui::EndChild() // Helper to create a child window / scrolling region that looks like a normal widget frame. bool ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags extra_flags) { - // FIXME-NEWBEGIN ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; PushStyleColor(ImGuiCol_ChildBg, style.Colors[ImGuiCol_FrameBg]); @@ -6760,22 +6761,22 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) } // FIXME-OPT - if (window->SkipItems || g.DebugBeginReturnValueCullDepth == g.CurrentWindowStack.Size) + bool debug_skip = (g.DebugBeginReturnValueCullDepth == g.CurrentWindowStack.Size) && (window->Flags & ImGuiWindowFlags_DockNodeHost) == 0; + if (window->SkipItems || debug_skip) { // The implicit fallback is NOT automatically ended as an exception to the rule, // allowing it to always be able to receive commands without crashing. - if (!window->IsFallbackWindow) - { - if (window->Flags & ImGuiWindowFlags_Popup) - EndPopup(); - else if (window->Flags & ImGuiWindowFlags_ChildWindow) - EndChild(); - else - End(); - } + if (window->IsFallbackWindow) + return true; + + if (window->Flags & ImGuiWindowFlags_Popup) + EndPopup(); + else if (window->Flags & ImGuiWindowFlags_ChildWindow) + EndChild(); + else + End(); return false; } - return true; } diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 76b8c957..535150a5 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -5422,15 +5422,13 @@ void ImGui::ShowAboutWindow(bool* p_open) static bool show_config_info = false; ImGui::Checkbox("Config/Build Information", &show_config_info); - if (show_config_info) + + ImGuiIO& io = ImGui::GetIO(); + ImGuiStyle& style = ImGui::GetStyle(); + const bool copy_to_clipboard = show_config_info && ImGui::Button("Copy to clipboard"); + const ImVec2 child_size = ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 18); + if (show_config_info && ImGui::BeginChildFrame(ImGui::GetID("cfg_infos"), child_size, ImGuiWindowFlags_NoMove)) { - ImGuiIO& io = ImGui::GetIO(); - ImGuiStyle& style = ImGui::GetStyle(); - - bool copy_to_clipboard = ImGui::Button("Copy to clipboard"); - ImVec2 child_size = ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 18); - ImGui::BeginChildFrame(ImGui::GetID("cfg_infos"), child_size, ImGuiWindowFlags_NoMove); - if (copy_to_clipboard) { ImGui::LogToClipboard(); @@ -5558,6 +5556,7 @@ void ImGui::ShowAboutWindow(bool* p_open) ImGui::LogText("\n```\n"); ImGui::LogFinish(); } + ImGui::EndChildFrame(); } ImGui::End(); } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 2e99e6ed..e9ce7489 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6131,7 +6131,7 @@ bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg) if (label_size.x > 0) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); - // FIXME-NEWBEGIN + // FIXME-NEWBEGIN: Use to be return true so we'll trigger more issues. return BeginChildFrame(id, frame_bb.GetSize()); }