Popups: Closing a popup restores the focused/nav window in place at the time of the popup opening, instead of restoring the window that was in the window stack at the time of the OpenPopup call. (#2517)

Among other things, this allows opening a popup while no window are focused, and pressing Escape to clear the focus again.
This commit is contained in:
omar
2019-04-28 21:52:12 +02:00
parent 3276b12765
commit bda2cde68e
5 changed files with 38 additions and 22 deletions

View File

@ -5818,9 +5818,10 @@ void ImGui::EndMainMenuBar()
EndMenuBar();
// When the user has left the menu layer (typically: closed menus through activation of an item), we restore focus to the previous window
// FIXME: With this strategy we won't be able to restore a NULL focus.
ImGuiContext& g = *GImGui;
if (g.CurrentWindow == g.NavWindow && g.NavLayer == 0)
FocusTopMostWindowIgnoringOne(g.NavWindow);
FocusTopMostWindowUnderOne(g.NavWindow, NULL);
End();
}
@ -5951,7 +5952,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
{
// Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers, so menus feels more reactive.
bool moving_within_opened_triangle = false;
if (g.HoveredWindow == window && g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].ParentWindow == window && !(window->Flags & ImGuiWindowFlags_MenuBar))
if (g.HoveredWindow == window && g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].SourceWindow == window && !(window->Flags & ImGuiWindowFlags_MenuBar))
{
if (ImGuiWindow* next_window = g.OpenPopupStack[g.BeginPopupStack.Size].Window)
{