Moving window to front of display and set focus (which happens to be back of our sorted list)
| 12922 | |
| 12923 | // Moving window to front of display and set focus (which happens to be back of our sorted list) |
| 12924 | void ImGui::FocusWindow(ImGuiWindow* window, ImGuiFocusRequestFlags flags) |
| 12925 | { |
| 12926 | ImGuiContext& g = *GImGui; |
| 12927 | |
| 12928 | // Modal check? |
| 12929 | if ((flags & ImGuiFocusRequestFlags_UnlessBelowModal) && (g.NavWindow != window)) // Early out in common case. |
| 12930 | if (ImGuiWindow* blocking_modal = FindBlockingModal(window)) |
| 12931 | { |
| 12932 | // This block would typically be reached in two situations: |
| 12933 | // - API call to FocusWindow() with a window under a modal and ImGuiFocusRequestFlags_UnlessBelowModal flag. |
| 12934 | // - User clicking on void or anything behind a modal while a modal is open (window == NULL) |
| 12935 | IMGUI_DEBUG_LOG_FOCUS("[focus] FocusWindow(\"%s\", UnlessBelowModal): prevented by \"%s\".\n", window ? window->Name : "<NULL>", blocking_modal->Name); |
| 12936 | if (window && window == window->RootWindow && (window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) |
| 12937 | BringWindowToDisplayBehind(window, blocking_modal); // Still bring right under modal. (FIXME: Could move in focus list too?) |
| 12938 | ClosePopupsOverWindow(GetTopMostPopupModal(), false); // Note how we need to use GetTopMostPopupModal() aad NOT blocking_modal, to handle nested modals |
| 12939 | return; |
| 12940 | } |
| 12941 | |
| 12942 | // Find last focused child (if any) and focus it instead. |
| 12943 | if ((flags & ImGuiFocusRequestFlags_RestoreFocusedChild) && window != NULL) |
| 12944 | window = NavRestoreLastChildNavWindow(window); |
| 12945 | |
| 12946 | // Apply focus |
| 12947 | if (g.NavWindow != window) |
| 12948 | { |
| 12949 | SetNavWindow(window); |
| 12950 | if (window && g.NavHighlightItemUnderNav) |
| 12951 | g.NavMousePosDirty = true; |
| 12952 | g.NavId = window ? window->NavLastIds[0] : 0; // Restore NavId |
| 12953 | g.NavLayer = ImGuiNavLayer_Main; |
| 12954 | SetNavFocusScope(window ? window->NavRootFocusScopeId : 0); |
| 12955 | g.NavIdIsAlive = false; |
| 12956 | g.NavLastValidSelectionUserData = ImGuiSelectionUserData_Invalid; |
| 12957 | |
| 12958 | // Close popups if any |
| 12959 | ClosePopupsOverWindow(window, false); |
| 12960 | } |
| 12961 | |
| 12962 | // Move the root window to the top of the pile |
| 12963 | IM_ASSERT(window == NULL || window->RootWindow != NULL); |
| 12964 | ImGuiWindow* focus_front_window = window ? window->RootWindow : NULL; // NB: In docking branch this is window->RootWindowDockStop |
| 12965 | ImGuiWindow* display_front_window = window ? window->RootWindow : NULL; |
| 12966 | |
| 12967 | // Steal active widgets. Some of the cases it triggers includes: |
| 12968 | // - Focus a window while an InputText in another window is active, if focus happens before the old InputText can run. |
| 12969 | // - When using Nav to activate menu items (due to timing of activating on press->new window appears->losing ActiveId) |
| 12970 | if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != focus_front_window) |
| 12971 | if (!g.ActiveIdNoClearOnFocusLoss) |
| 12972 | ClearActiveID(); |
| 12973 | |
| 12974 | // Passing NULL allow to disable keyboard focus |
| 12975 | if (!window) |
| 12976 | return; |
| 12977 | |
| 12978 | // Bring to front |
| 12979 | BringWindowToFocusFront(focus_front_window); |
| 12980 | if (((window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) |
| 12981 | BringWindowToDisplayFront(display_front_window); |
nothing calls this directly
no outgoing calls
no test coverage detected