MCPcopy Create free account
hub / github.com/RenderKit/embree / NavUpdateWindowing

Method NavUpdateWindowing

tutorials/common/imgui/imgui.cpp:11494–11676  ·  view source on GitHub ↗

Windowing management mode Keyboard: CTRL+Tab (change focus/move/resize), Alt (toggle menu layer) Gamepad: Hold Menu/Square (change focus/move/resize), Tap Menu/Square (toggle menu layer)

Source from the content-addressed store, hash-verified

11492// Keyboard: CTRL+Tab (change focus/move/resize), Alt (toggle menu layer)
11493// Gamepad: Hold Menu/Square (change focus/move/resize), Tap Menu/Square (toggle menu layer)
11494static void ImGui::NavUpdateWindowing()
11495{
11496 ImGuiContext& g = *GImGui;
11497 ImGuiIO& io = g.IO;
11498
11499 ImGuiWindow* apply_focus_window = NULL;
11500 bool apply_toggle_layer = false;
11501
11502 ImGuiWindow* modal_window = GetTopMostPopupModal();
11503 bool allow_windowing = (modal_window == NULL);
11504 if (!allow_windowing)
11505 g.NavWindowingTarget = NULL;
11506
11507 // Fade out
11508 if (g.NavWindowingTargetAnim && g.NavWindowingTarget == NULL)
11509 {
11510 g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha - io.DeltaTime * 10.0f, 0.0f);
11511 if (g.DimBgRatio <= 0.0f && g.NavWindowingHighlightAlpha <= 0.0f)
11512 g.NavWindowingTargetAnim = NULL;
11513 }
11514
11515 // Start CTRL+Tab or Square+L/R window selection
11516 const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
11517 const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
11518 const bool keyboard_next_window = allow_windowing && g.ConfigNavWindowingKeyNext && Shortcut(g.ConfigNavWindowingKeyNext, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat | ImGuiInputFlags_RouteAlways);
11519 const bool keyboard_prev_window = allow_windowing && g.ConfigNavWindowingKeyPrev && Shortcut(g.ConfigNavWindowingKeyPrev, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat | ImGuiInputFlags_RouteAlways);
11520 const bool start_windowing_with_gamepad = allow_windowing && nav_gamepad_active && !g.NavWindowingTarget && IsKeyPressed(ImGuiKey_NavGamepadMenu, 0, ImGuiInputFlags_None);
11521 const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && (keyboard_next_window || keyboard_prev_window); // Note: enabled even without NavEnableKeyboard!
11522 if (start_windowing_with_gamepad || start_windowing_with_keyboard)
11523 if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1))
11524 {
11525 g.NavWindowingTarget = g.NavWindowingTargetAnim = window->RootWindow;
11526 g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f;
11527 g.NavWindowingAccumDeltaPos = g.NavWindowingAccumDeltaSize = ImVec2(0.0f, 0.0f);
11528 g.NavWindowingToggleLayer = start_windowing_with_gamepad ? true : false; // Gamepad starts toggling layer
11529 g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_Keyboard : ImGuiInputSource_Gamepad;
11530 }
11531
11532 // Gamepad update
11533 g.NavWindowingTimer += io.DeltaTime;
11534 if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_Gamepad)
11535 {
11536 // Highlight only appears after a brief time holding the button, so that a fast tap on PadMenu (to toggle NavLayer) doesn't add visual noise
11537 g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f));
11538
11539 // Select window to focus
11540 const int focus_change_dir = (int)IsKeyPressed(ImGuiKey_GamepadL1) - (int)IsKeyPressed(ImGuiKey_GamepadR1);
11541 if (focus_change_dir != 0)
11542 {
11543 NavUpdateWindowingHighlightWindow(focus_change_dir);
11544 g.NavWindowingHighlightAlpha = 1.0f;
11545 }
11546
11547 // Single press toggles NavLayer, long press with L/R apply actual focus on release (until then the window was merely rendered top-most)
11548 if (!IsKeyDown(ImGuiKey_NavGamepadMenu))
11549 {
11550 g.NavWindowingToggleLayer &= (g.NavWindowingHighlightAlpha < 1.0f); // Once button was held long enough we don't consider it a tap-to-toggle-layer press anymore.
11551 if (g.NavWindowingToggleLayer && g.NavWindow)

Callers

nothing calls this directly

Calls 7

ImMaxFunction · 0.85
FindWindowNavFocusableFunction · 0.85
ImVec2Function · 0.85
ImSaturateFunction · 0.85
ImMinFunction · 0.85
ImFloorFunction · 0.85

Tested by

no test coverage detected