From 1d2b8ac1f3ea3c9207cdbb4d83dfa5a881608747 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 10 May 2023 22:29:17 +0200 Subject: [PATCH] fix: Closing popups using Esc causing them to re-appear --- main/source/window/window.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index dfdafcfe4..cced947e5 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -530,17 +530,24 @@ namespace hex { // Draw popup stack { + static bool popupDisplaying = false; + static bool positionSet = false; + static bool sizeSet = false; + + static std::unique_ptr currPopup; + static LangEntry name(""); + if (auto &popups = impl::PopupBase::getOpenPopups(); !popups.empty()) { - static bool popupDisplaying = false; - static bool positionSet = false; - static bool sizeSet = false; + if (!ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId)) { + currPopup = std::move(popups.back()); + name = LangEntry(currPopup->getUnlocalizedName()); - auto &currPopup = popups.back(); - const auto &name = LangEntry(currPopup->getUnlocalizedName()); - - if (!ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId)) ImGui::OpenPopup(name); + popups.pop_back(); + } + } + if (currPopup != nullptr) { bool open = true; const auto &minSize = currPopup->getMinSize(); @@ -585,8 +592,7 @@ namespace hex { log::debug("Closing popup '{}'", name); positionSet = sizeSet = false; - if (auto it = std::find(popups.begin(), popups.end(), currPopup); it != popups.end()) - popups.erase(it); + currPopup = nullptr; } } }