Skip to content

Commit

Permalink
Allow stacking popups, not really useful yet (wip #126)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed May 7, 2015
1 parent dd2a578 commit 33e8fb8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ struct ImGuiState
ImVector<ImGuiWindow*> WindowsSortBuffer;
ImGuiWindow* CurrentWindow; // Being drawn into
ImVector<ImGuiWindow*> CurrentWindowStack;
int CurrentPopupStackSize;
ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
ImGuiWindow* HoveredWindow; // Will catch mouse inputs
ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
Expand Down Expand Up @@ -1197,6 +1198,7 @@ struct ImGuiState
FrameCount = 0;
FrameCountRendered = -1;
CurrentWindow = NULL;
CurrentPopupStackSize = 0;
FocusedWindow = NULL;
HoveredWindow = NULL;
HoveredRootWindow = NULL;
Expand Down Expand Up @@ -2893,21 +2895,28 @@ void ImGui::EndTooltip()

void ImGui::BeginPopup(bool* p_opened)
{
ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
IM_ASSERT(p_opened != NULL); // Must provide a bool at the moment

ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGuiWindowFlags flags = ImGuiWindowFlags_Popup|ImGuiWindowFlags_ShowBorders|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
float alpha = 1.0f;
ImGui::Begin("##Popup", p_opened, ImVec2(0.0f, 0.0f), alpha, flags);

char name[20];
ImFormatString(name, 20, "##Popup%02d", g.CurrentPopupStackSize++);
ImGui::Begin(name, p_opened, ImVec2(0.0f, 0.0f), alpha, flags);

if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
GetCurrentWindow()->Flags &= ~ImGuiWindowFlags_ShowBorders;
}

void ImGui::EndPopup()
{
ImGuiState& g = *GImGui;
IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Popup);
IM_ASSERT(g.CurrentPopupStackSize > 0);
g.CurrentPopupStackSize--;
ImGui::End();
ImGui::PopStyleVar();
}
Expand Down Expand Up @@ -3133,6 +3142,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
const bool window_was_visible = (window->LastFrameDrawn == current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on

// Add to stack
ImGuiWindow* parent_window = !g.CurrentWindowStack.empty() ? g.CurrentWindowStack.back() : NULL;
g.CurrentWindowStack.push_back(window);
SetCurrentWindow(window);

Expand Down Expand Up @@ -3165,9 +3175,6 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
g.SetNextWindowFocus = false;
}

// Find parent
ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL;

// Update known root window (if we are a child window, otherwise window == window->RootWindow)
size_t root_idx = g.CurrentWindowStack.size() - 1;
while (root_idx > 0)
Expand Down

0 comments on commit 33e8fb8

Please sign in to comment.