From cf037b4769650da319f8f6a039be1f394b30c7f2 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 21 Nov 2014 13:23:22 +0000 Subject: [PATCH] PushStyleColor/PushStyleVar can be used outside the scope of a window. Added 'count' parameter to PopStyleColor/PopStyleVar --- imgui.cpp | 49 ++++++++++++++++++++++++++----------------------- imgui.h | 4 ++-- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 17188a1b..07b02a0f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -624,8 +624,6 @@ struct ImGuiDrawContext ImVector AllowKeyboardFocus; ImVector ItemWidth; ImVector TextWrapPos; - ImVector ColorModifiers; - ImVector StyleModifiers; ImGuiColorEditMode ColorEditMode; ImGuiStorage* StateStorage; int OpenNextNode; @@ -734,6 +732,8 @@ struct ImGuiState float SettingsDirtyTimer; ImVector Settings; ImVec2 NewWindowDefaultPos; + ImVector ColorModifiers; + ImVector StyleModifiers; // Render ImVector RenderDrawLists; @@ -2366,8 +2366,6 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I window->DC.AllowKeyboardFocus.push_back(true); window->DC.TextWrapPos.resize(0); window->DC.TextWrapPos.push_back(-1.0f); // disabled - window->DC.ColorModifiers.resize(0); - window->DC.StyleModifiers.resize(0); window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect; window->DC.ColumnsCurrent = 0; window->DC.ColumnsCount = 1; @@ -2549,23 +2547,25 @@ void ImGui::PopTextWrapPos() void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col) { ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); ImGuiColMod backup; backup.Col = idx; backup.PreviousValue = g.Style.Colors[idx]; - window->DC.ColorModifiers.push_back(backup); + g.ColorModifiers.push_back(backup); g.Style.Colors[idx] = col; } -void ImGui::PopStyleColor() +void ImGui::PopStyleColor(int count) { ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - ImGuiColMod& backup = window->DC.ColorModifiers.back(); - g.Style.Colors[backup.Col] = backup.PreviousValue; - window->DC.ColorModifiers.pop_back(); + while (count > 0) + { + ImGuiColMod& backup = g.ColorModifiers.back(); + g.Style.Colors[backup.Col] = backup.PreviousValue; + g.ColorModifiers.pop_back(); + count--; + } } static float* GetStyleVarFloatAddr(ImGuiStyleVar idx) @@ -2595,41 +2595,44 @@ static ImVec2* GetStyleVarVec2Addr(ImGuiStyleVar idx) void ImGui::PushStyleVar(ImGuiStyleVar idx, float val) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; float* pvar = GetStyleVarFloatAddr(idx); IM_ASSERT(pvar != NULL); // Called wrong function? ImGuiStyleMod backup; backup.Var = idx; backup.PreviousValue = ImVec2(*pvar, 0.0f); - window->DC.StyleModifiers.push_back(backup); + g.StyleModifiers.push_back(backup); *pvar = val; } void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; ImVec2* pvar = GetStyleVarVec2Addr(idx); IM_ASSERT(pvar != NULL); // Called wrong function? ImGuiStyleMod backup; backup.Var = idx; backup.PreviousValue = *pvar; - window->DC.StyleModifiers.push_back(backup); + g.StyleModifiers.push_back(backup); *pvar = val; } -void ImGui::PopStyleVar() +void ImGui::PopStyleVar(int count) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; - ImGuiStyleMod& backup = window->DC.StyleModifiers.back(); - if (float* pvar_f = GetStyleVarFloatAddr(backup.Var)) - *pvar_f = backup.PreviousValue.x; - else if (ImVec2* pvar_v = GetStyleVarVec2Addr(backup.Var)) - *pvar_v = backup.PreviousValue; - window->DC.StyleModifiers.pop_back(); + while (count > 0) + { + ImGuiStyleMod& backup = g.StyleModifiers.back(); + if (float* pvar_f = GetStyleVarFloatAddr(backup.Var)) + *pvar_f = backup.PreviousValue.x; + else if (ImVec2* pvar_v = GetStyleVarVec2Addr(backup.Var)) + *pvar_v = backup.PreviousValue; + g.StyleModifiers.pop_back(); + } } const char* ImGui::GetStyleColorName(ImGuiCol idx) diff --git a/imgui.h b/imgui.h index a2dbaa09..2ed820fb 100644 --- a/imgui.h +++ b/imgui.h @@ -172,10 +172,10 @@ namespace ImGui IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets. IMGUI_API void PopAllowKeyboardFocus(); IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4& col); - IMGUI_API void PopStyleColor(); + IMGUI_API void PopStyleColor(int count = 1); IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val); IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val); - IMGUI_API void PopStyleVar(); + IMGUI_API void PopStyleVar(int count = 1); IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space. IMGUI_API void PopTextWrapPos();