From 440f2576884909d9a27a36f581d98eb9cfc56bec Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 16 Sep 2022 22:08:11 +0200 Subject: [PATCH] Popups & Modals: fixed nested Begin() being erroneously input-inhibited. (useful for e.g. #718, #4461 and probably other things) --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 14 ++++++++++---- imgui.h | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index aa0cab364..96e61d25d 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -84,6 +84,9 @@ Breaking changes: Other Changes: +- Popups & Modals: fixed nested Begin() being erroneously input-inhibited. While it is + unusual, you can nest a Begin() inside a popup or modal, it is occasionally useful to + achieve certains things (e.g. some ways to implement suggestion popup #718, #4461). - InputText: added experimental io.ConfigInputTextEnterKeepActive feature to make pressing Enter keep the input active and select all text. - InputText: numerical fields automatically accept full-width characters (U+FF01..U+FF5E) diff --git a/imgui.cpp b/imgui.cpp index d35f04258..a4322bdf7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3539,11 +3539,17 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla if (focused_root_window->WasActive && focused_root_window != window->RootWindow) { // For the purpose of those flags we differentiate "standard popup" from "modal popup" - // NB: The order of those two tests is important because Modal windows are also Popups. + // NB: The 'else' is important because Modal windows are also Popups. + bool want_inhibit = false; if (focused_root_window->Flags & ImGuiWindowFlags_Modal) - return false; - if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) - return false; + want_inhibit = true; + else if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + want_inhibit = true; + + // Inhibit hover unless the window is within the stack of our modal/popup + if (want_inhibit) + if (!ImGui::IsWindowWithinBeginStackOf(window->RootWindow, focused_root_window)) + return false; } return true; } diff --git a/imgui.h b/imgui.h index 4622336af..552a5f598 100644 --- a/imgui.h +++ b/imgui.h @@ -23,7 +23,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') #define IMGUI_VERSION "1.89 WIP" -#define IMGUI_VERSION_NUM 18819 +#define IMGUI_VERSION_NUM 18820 #define IMGUI_HAS_TABLE /*