Skip to content

Commit

Permalink
Misc: moved StacSizeOnBegin out of window instance into window stack …
Browse files Browse the repository at this point in the history
…data.
  • Loading branch information
ocornut committed Sep 15, 2021
1 parent 66cd21d commit 2d0a6a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
21 changes: 11 additions & 10 deletions imgui.cpp
Expand Up @@ -5845,12 +5845,12 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)

// Add to stack
// We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow()
g.CurrentWindow = window;
ImGuiWindowStackData window_stack_data;
window_stack_data.Window = window;
window_stack_data.ParentLastItemDataBackup = g.LastItemData;
window_stack_data.StackSizesOnBegin.SetToCurrentState();
g.CurrentWindowStack.push_back(window_stack_data);
g.CurrentWindow = window;
window->DC.StackSizesOnBegin.SetToCurrentState();
g.CurrentWindow = NULL;

if (flags & ImGuiWindowFlags_Popup)
Expand Down Expand Up @@ -6465,10 +6465,10 @@ void ImGui::End()

// Pop from window stack
g.LastItemData = g.CurrentWindowStack.back().ParentLastItemDataBackup;
g.CurrentWindowStack.pop_back();
if (window->Flags & ImGuiWindowFlags_Popup)
g.BeginPopupStack.pop_back();
window->DC.StackSizesOnBegin.CompareWithCurrentState();
g.CurrentWindowStack.back().StackSizesOnBegin.CompareWithCurrentState();
g.CurrentWindowStack.pop_back();
SetCurrentWindow(g.CurrentWindowStack.Size == 0 ? NULL : g.CurrentWindowStack.back().Window);
}

Expand Down Expand Up @@ -7348,6 +7348,7 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo
}

ImGuiWindow* window = g.CurrentWindow;
ImGuiStackSizes* stack_sizes = &g.CurrentWindowStack.back().StackSizesOnBegin;
IM_ASSERT(window != NULL);
while (g.CurrentTabBar != NULL) //-V1044
{
Expand All @@ -7359,7 +7360,7 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo
if (log_callback) log_callback(user_data, "Recovered from missing TreePop() in '%s'", window->Name);
TreePop();
}
while (g.GroupStack.Size > window->DC.StackSizesOnBegin.SizeOfGroupStack)
while (g.GroupStack.Size > stack_sizes->SizeOfGroupStack)
{
if (log_callback) log_callback(user_data, "Recovered from missing EndGroup() in '%s'", window->Name);
EndGroup();
Expand All @@ -7369,27 +7370,27 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo
if (log_callback) log_callback(user_data, "Recovered from missing PopID() in '%s'", window->Name);
PopID();
}
while (g.DisabledStackSize > window->DC.StackSizesOnBegin.SizeOfDisabledStack)
while (g.DisabledStackSize > stack_sizes->SizeOfDisabledStack)
{
if (log_callback) log_callback(user_data, "Recovered from missing EndDisabled() in '%s'", window->Name);
EndDisabled();
}
while (g.ColorStack.Size > window->DC.StackSizesOnBegin.SizeOfColorStack)
while (g.ColorStack.Size > stack_sizes->SizeOfColorStack)
{
if (log_callback) log_callback(user_data, "Recovered from missing PopStyleColor() in '%s' for ImGuiCol_%s", window->Name, GetStyleColorName(g.ColorStack.back().Col));
PopStyleColor();
}
while (g.ItemFlagsStack.Size > window->DC.StackSizesOnBegin.SizeOfItemFlagsStack)
while (g.ItemFlagsStack.Size > stack_sizes->SizeOfItemFlagsStack)
{
if (log_callback) log_callback(user_data, "Recovered from missing PopItemFlag() in '%s'", window->Name);
PopItemFlag();
}
while (g.StyleVarStack.Size > window->DC.StackSizesOnBegin.SizeOfStyleVarStack)
while (g.StyleVarStack.Size > stack_sizes->SizeOfStyleVarStack)
{
if (log_callback) log_callback(user_data, "Recovered from missing PopStyleVar() in '%s'", window->Name);
PopStyleVar();
}
while (g.FocusScopeStack.Size > window->DC.StackSizesOnBegin.SizeOfFocusScopeStack)
while (g.FocusScopeStack.Size > stack_sizes->SizeOfFocusScopeStack)
{
if (log_callback) log_callback(user_data, "Recovered from missing PopFocusScope() in '%s'", window->Name);
PopFocusScope();
Expand Down
36 changes: 18 additions & 18 deletions imgui_internal.h
Expand Up @@ -1123,11 +1123,29 @@ struct ImGuiLastItemData
ImGuiLastItemData() { memset(this, 0, sizeof(*this)); }
};

struct IMGUI_API ImGuiStackSizes
{
short SizeOfIDStack;
short SizeOfColorStack;
short SizeOfStyleVarStack;
short SizeOfFontStack;
short SizeOfFocusScopeStack;
short SizeOfGroupStack;
short SizeOfItemFlagsStack;
short SizeOfBeginPopupStack;
short SizeOfDisabledStack;

ImGuiStackSizes() { memset(this, 0, sizeof(*this)); }
void SetToCurrentState();
void CompareWithCurrentState();
};

// Data saved for each window pushed into the stack
struct ImGuiWindowStackData
{
ImGuiWindow* Window;
ImGuiLastItemData ParentLastItemDataBackup;
ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting
};

struct ImGuiShrinkWidthItem
Expand Down Expand Up @@ -1373,23 +1391,6 @@ struct ImGuiMetricsConfig
}
};

struct IMGUI_API ImGuiStackSizes
{
short SizeOfIDStack;
short SizeOfColorStack;
short SizeOfStyleVarStack;
short SizeOfFontStack;
short SizeOfFocusScopeStack;
short SizeOfGroupStack;
short SizeOfItemFlagsStack;
short SizeOfBeginPopupStack;
short SizeOfDisabledStack;

ImGuiStackSizes() { memset(this, 0, sizeof(*this)); }
void SetToCurrentState();
void CompareWithCurrentState();
};

//-----------------------------------------------------------------------------
// [SECTION] Generic context hooks
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1867,7 +1868,6 @@ struct IMGUI_API ImGuiWindowTempData
float TextWrapPos; // Current text wrap pos.
ImVector<float> ItemWidthStack; // Store item widths to restore (attention: .back() is not == ItemWidth)
ImVector<float> TextWrapPosStack; // Store text wrap pos to restore (attention: .back() is not == TextWrapPos)
ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting // FIXME: Can be moved to ImGuiWindowStackData
};

// Storage for one window
Expand Down

0 comments on commit 2d0a6a4

Please sign in to comment.