Process NavCancel input (to close a popup, get back to parent, clear focus) FIXME: In order to support e.g. Escape to clear a selection we'll need: - either to store the equivalent of ActiveIdUsingKeyInputMask for a FocusScope and test for it. - either to move most/all of those tests to the epilogue/end functions of the scope they are dealing with (e.g. exit child window in EndChild()) or in EndFr
| 11258 | // - either to store the equivalent of ActiveIdUsingKeyInputMask for a FocusScope and test for it. |
| 11259 | // - either to move most/all of those tests to the epilogue/end functions of the scope they are dealing with (e.g. exit child window in EndChild()) or in EndFrame(), to allow an earlier intercept |
| 11260 | static void ImGui::NavUpdateCancelRequest() |
| 11261 | { |
| 11262 | ImGuiContext& g = *GImGui; |
| 11263 | const bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; |
| 11264 | const bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; |
| 11265 | if (!(nav_keyboard_active && IsKeyPressed(ImGuiKey_Escape, ImGuiKeyOwner_None)) && !(nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadCancel, ImGuiKeyOwner_None))) |
| 11266 | return; |
| 11267 | |
| 11268 | IMGUI_DEBUG_LOG_NAV("[nav] NavUpdateCancelRequest()\n"); |
| 11269 | if (g.ActiveId != 0) |
| 11270 | { |
| 11271 | ClearActiveID(); |
| 11272 | } |
| 11273 | else if (g.NavLayer != ImGuiNavLayer_Main) |
| 11274 | { |
| 11275 | // Leave the "menu" layer |
| 11276 | NavRestoreLayer(ImGuiNavLayer_Main); |
| 11277 | NavRestoreHighlightAfterMove(); |
| 11278 | } |
| 11279 | else if (g.NavWindow && g.NavWindow != g.NavWindow->RootWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->ParentWindow) |
| 11280 | { |
| 11281 | // Exit child window |
| 11282 | ImGuiWindow* child_window = g.NavWindow; |
| 11283 | ImGuiWindow* parent_window = g.NavWindow->ParentWindow; |
| 11284 | IM_ASSERT(child_window->ChildId != 0); |
| 11285 | ImRect child_rect = child_window->Rect(); |
| 11286 | FocusWindow(parent_window); |
| 11287 | SetNavID(child_window->ChildId, ImGuiNavLayer_Main, 0, WindowRectAbsToRel(parent_window, child_rect)); |
| 11288 | NavRestoreHighlightAfterMove(); |
| 11289 | } |
| 11290 | else if (g.OpenPopupStack.Size > 0 && g.OpenPopupStack.back().Window != NULL && !(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal)) |
| 11291 | { |
| 11292 | // Close open popup/menu |
| 11293 | ClosePopupToLevel(g.OpenPopupStack.Size - 1, true); |
| 11294 | } |
| 11295 | else |
| 11296 | { |
| 11297 | // Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were |
| 11298 | if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow))) |
| 11299 | g.NavWindow->NavLastIds[0] = 0; |
| 11300 | g.NavId = 0; |
| 11301 | } |
| 11302 | } |
| 11303 | |
| 11304 | // Handle PageUp/PageDown/Home/End keys |
| 11305 | // Called from NavUpdateCreateMoveRequest() which will use our output to create a move request |
nothing calls this directly
no test coverage detected