Focus: move focused child restore code in FocusWindow() with ImGuiFocusRequestFlags_RestoreFocusedChild flag. (#6357)

# Conflicts:
#	imgui.cpp
This commit is contained in:
ocornut
2023-04-21 17:46:41 +02:00
parent 30eceaf95f
commit 01ca196530
3 changed files with 14 additions and 17 deletions

View File

@ -4623,7 +4623,7 @@ void ImGui::NewFrame()
// Closing the focused window restore focus to the first active root window in descending z-order
if (g.NavWindow && !g.NavWindow->WasActive)
FocusTopMostWindowUnderOne(NULL, NULL, NULL, ImGuiFocusRequestFlags_None);
FocusTopMostWindowUnderOne(NULL, NULL, NULL, ImGuiFocusRequestFlags_RestoreFocusedChild);
// No window should be open at the beginning of the frame.
// But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
@ -6941,6 +6941,10 @@ void ImGui::FocusWindow(ImGuiWindow* window, ImGuiFocusRequestFlags flags)
return;
}
// Find last focused child (if any) and focus it instead.
if ((flags & ImGuiFocusRequestFlags_RestoreFocusedChild) && window != NULL)
window = NavRestoreLastChildNavWindow(window);
// Apply focus
if (g.NavWindow != window)
{
@ -7003,8 +7007,7 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind
continue;
if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs))
{
ImGuiWindow* focus_window = NavRestoreLastChildNavWindow(window);
FocusWindow(focus_window, flags);
FocusWindow(window, flags);
return;
}
}
@ -10272,16 +10275,9 @@ void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_
{
ImGuiWindow* focus_window = (popup_window && popup_window->Flags & ImGuiWindowFlags_ChildMenu) ? popup_window->ParentWindow : popup_backup_nav_window;
if (focus_window && !focus_window->WasActive && popup_window)
{
// Fallback
FocusTopMostWindowUnderOne(popup_window, NULL, NULL, ImGuiFocusRequestFlags_None);
}
FocusTopMostWindowUnderOne(popup_window, NULL, NULL, ImGuiFocusRequestFlags_RestoreFocusedChild); // Fallback
else
{
if (g.NavLayer == ImGuiNavLayer_Main && focus_window)
focus_window = NavRestoreLastChildNavWindow(focus_window);
FocusWindow(focus_window);
}
FocusWindow(focus_window, (g.NavLayer == ImGuiNavLayer_Main) ? ImGuiFocusRequestFlags_RestoreFocusedChild : ImGuiFocusRequestFlags_None);
}
}
@ -11854,7 +11850,7 @@ static void ImGui::NavUpdateWindowing()
bool apply_toggle_layer = false;
ImGuiWindow* modal_window = GetTopMostPopupModal();
bool allow_windowing = (modal_window == NULL);
bool allow_windowing = (modal_window == NULL); // FIXME: This prevent CTRL+TAB from being usable with windows over a popup
if (!allow_windowing)
g.NavWindowingTarget = NULL;
@ -11983,9 +11979,9 @@ static void ImGui::NavUpdateWindowing()
{
ClearActiveID();
NavRestoreHighlightAfterMove();
apply_focus_window = NavRestoreLastChildNavWindow(apply_focus_window);
ClosePopupsOverWindow(apply_focus_window, false);
FocusWindow(apply_focus_window);
FocusWindow(apply_focus_window, ImGuiFocusRequestFlags_RestoreFocusedChild);
apply_focus_window = g.NavWindow;
if (apply_focus_window->NavLastIds[0] == 0)
NavInitWindow(apply_focus_window, false);