From 55d873875e62d952f1b26ac87ba3bd95de2f29bc Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Oct 2017 15:47:55 +0200 Subject: [PATCH] Begin: Work toward obsoleting the 5-arguments Begin() overload. (1) --- imgui.cpp | 29 +++++++++++++++++++---------- imgui_internal.h | 2 ++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9e969385..dcd92148 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4010,6 +4010,17 @@ static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window) return scroll; } +static ImGuiCol GetWindowBgColorIdxFromFlags(ImGuiWindowFlags flags) +{ + if (flags & ImGuiWindowFlags_ComboBox) + return ImGuiCol_ComboBg; + if (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) + return ImGuiCol_PopupBg; + if (flags & ImGuiWindowFlags_ChildWindow) + return ImGuiCol_ChildWindowBg; + return ImGuiCol_WindowBg; +} + // Push a new ImGui window to add widgets to. // - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair. // - Begin/End can be called multiple times during the frame with the same window name to append content. @@ -4021,10 +4032,15 @@ static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window) // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiCond_FirstUseEver) prior to calling Begin(). bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { - return ImGui::Begin(name, p_open, ImVec2(0.f, 0.f), -1.0f, flags); + return BeginEx(name, p_open, ImVec2(0.f, 0.f), -1.0f, flags); } bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha, ImGuiWindowFlags flags) +{ + return BeginEx(name, p_open, size_on_first_use, bg_alpha, flags); +} + +bool ImGui::BeginEx(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha, ImGuiWindowFlags flags) { ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; @@ -4371,13 +4387,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us window->BorderSize = (flags & ImGuiWindowFlags_ShowBorders) ? 1.0f : 0.0f; // Window background, Default Alpha - ImGuiCol bg_color_idx = ImGuiCol_WindowBg; - if ((flags & ImGuiWindowFlags_ComboBox) != 0) - bg_color_idx = ImGuiCol_ComboBg; - else if ((flags & ImGuiWindowFlags_Tooltip) != 0 || (flags & ImGuiWindowFlags_Popup) != 0) - bg_color_idx = ImGuiCol_PopupBg; - else if ((flags & ImGuiWindowFlags_ChildWindow) != 0) - bg_color_idx = ImGuiCol_ChildWindowBg; + ImGuiCol bg_color_idx = GetWindowBgColorIdxFromFlags(flags); ImVec4 bg_color = style.Colors[bg_color_idx]; // We don't use GetColorU32() because bg_alpha is assigned (not multiplied) below if (bg_alpha >= 0.0f) bg_color.w = bg_alpha; @@ -5151,8 +5161,7 @@ void ImGui::SetWindowSize(const ImVec2& size, ImGuiCond cond) void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiCond cond) { - ImGuiWindow* window = FindWindowByName(name); - if (window) + if (ImGuiWindow* window = FindWindowByName(name)) SetWindowSize(window, size, cond); } diff --git a/imgui_internal.h b/imgui_internal.h index 6c4f8db5..ea67e9df 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -782,6 +782,8 @@ namespace ImGui IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled); IMGUI_API void PopItemFlag(); + IMGUI_API bool BeginEx(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha, ImGuiWindowFlags flags); + IMGUI_API void OpenPopupEx(ImGuiID id, bool reopen_existing); IMGUI_API void ClosePopup(ImGuiID id); IMGUI_API bool IsPopupOpen(ImGuiID id);