#include "imgui_context_extensions.h" #include static std::stack CONTEXT_STACK; namespace ImGui { void PushContextSwitch(ImGuiContext *newCtx) { CONTEXT_STACK.push(ImGui::GetCurrentContext()); // save current context ImGui::SetCurrentContext(newCtx); // perform context switch } void PopContextSwitch() { if (CONTEXT_STACK.empty()) return; ImGui::SetCurrentContext(CONTEXT_STACK.top()); // restore previous context CONTEXT_STACK.pop(); } ScopedContextSwitch::ScopedContextSwitch(ImGuiContext *newCtx) { ImGui::PushContextSwitch(newCtx); } ScopedContextSwitch::~ScopedContextSwitch() { ImGui::PopContextSwitch(); } } // namespace ImGui