Moving window to front of display and set focus (which happens to be back of our sorted list)
| 13012 | |
| 13013 | // Moving window to front of display and set focus (which happens to be back of our sorted list) |
| 13014 | void ImGui::FocusWindow(ImGuiWindow* window, ImGuiFocusRequestFlags flags) |
| 13015 | { |
| 13016 | ImGuiContext& g = *GImGui; |
| 13017 | |
| 13018 | // Modal check? |
| 13019 | if ((flags & ImGuiFocusRequestFlags_UnlessBelowModal) && (g.NavWindow != window)) // Early out in common case. |
| 13020 | if (ImGuiWindow* blocking_modal = FindBlockingModal(window)) |
| 13021 | { |
| 13022 | // This block would typically be reached in two situations: |
| 13023 | // - API call to FocusWindow() with a window under a modal and ImGuiFocusRequestFlags_UnlessBelowModal flag. |
| 13024 | // - User clicking on void or anything behind a modal while a modal is open (window == NULL) |
| 13025 | IMGUI_DEBUG_LOG_FOCUS("[focus] FocusWindow(\"%s\", UnlessBelowModal): prevented by \"%s\".\n", window ? window->Name : "<NULL>", blocking_modal->Name); |
| 13026 | if (window && window == window->RootWindow && (window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) |
| 13027 | BringWindowToDisplayBehind(window, blocking_modal); // Still bring right under modal. (FIXME: Could move in focus list too?) |
| 13028 | ClosePopupsOverWindow(GetTopMostPopupModal(), false); // Note how we need to use GetTopMostPopupModal() aad NOT blocking_modal, to handle nested modals |
| 13029 | return; |
| 13030 | } |
| 13031 | |
| 13032 | // Find last focused child (if any) and focus it instead. |
| 13033 | if ((flags & ImGuiFocusRequestFlags_RestoreFocusedChild) && window != NULL) |
| 13034 | window = NavRestoreLastChildNavWindow(window); |
| 13035 | |
| 13036 | // Apply focus |
| 13037 | if (g.NavWindow != window) |
| 13038 | { |
| 13039 | SetNavWindow(window); |
| 13040 | if (window && g.NavHighlightItemUnderNav) |
| 13041 | g.NavMousePosDirty = true; |
| 13042 | g.NavId = window ? window->NavLastIds[0] : 0; // Restore NavId |
| 13043 | g.NavLayer = ImGuiNavLayer_Main; |
| 13044 | SetNavFocusScope(window ? window->NavRootFocusScopeId : 0); |
| 13045 | g.NavIdIsAlive = false; |
| 13046 | g.NavLastValidSelectionUserData = ImGuiSelectionUserData_Invalid; |
| 13047 | |
| 13048 | // Close popups if any |
| 13049 | ClosePopupsOverWindow(window, false); |
| 13050 | } |
| 13051 | |
| 13052 | // Move the root window to the top of the pile |
| 13053 | IM_ASSERT(window == NULL || window->RootWindow != NULL); |
| 13054 | ImGuiWindow* focus_front_window = window ? window->RootWindow : NULL; // NB: In docking branch this is window->RootWindowDockStop |
| 13055 | ImGuiWindow* display_front_window = window ? window->RootWindow : NULL; |
| 13056 | |
| 13057 | // Steal active widgets. Some of the cases it triggers includes: |
| 13058 | // - Focus a window while an InputText in another window is active, if focus happens before the old InputText can run. |
| 13059 | // - When using Nav to activate menu items (due to timing of activating on press->new window appears->losing ActiveId) |
| 13060 | if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != focus_front_window) |
| 13061 | if (!g.ActiveIdNoClearOnFocusLoss) |
| 13062 | ClearActiveID(); |
| 13063 | |
| 13064 | // Passing NULL allow to disable keyboard focus |
| 13065 | if (!window) |
| 13066 | return; |
| 13067 | |
| 13068 | // Bring to front |
| 13069 | BringWindowToFocusFront(focus_front_window); |
| 13070 | if (((window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) |
| 13071 | BringWindowToDisplayFront(display_front_window); |
nothing calls this directly
no outgoing calls
no test coverage detected