| 3039 | } |
| 3040 | |
| 3041 | static void ImGui::NavUpdate() |
| 3042 | { |
| 3043 | ImGuiContext& g = *GImGui; |
| 3044 | g.IO.WantMoveMouse = false; |
| 3045 | |
| 3046 | #if 0 |
| 3047 | if (g.NavScoringCount > 0) printf("[%05d] NavScoringCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.FrameCount, g.NavScoringCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest); |
| 3048 | #endif |
| 3049 | |
| 3050 | // Update Keyboard->Nav inputs mapping |
| 3051 | memset(g.IO.NavInputs + ImGuiNavInput_InternalStart_, 0, (ImGuiNavInput_COUNT - ImGuiNavInput_InternalStart_) * sizeof(g.IO.NavInputs[0])); |
| 3052 | if (g.IO.NavFlags & ImGuiNavFlags_EnableKeyboard) |
| 3053 | { |
| 3054 | #define NAV_MAP_KEY(_KEY, _NAV_INPUT) \ |
| 3055 | if (g.IO.KeyMap[_KEY] != -1 && IsKeyDown(g.IO.KeyMap[_KEY])) g.IO.NavInputs[_NAV_INPUT] = 1.0f; |
| 3056 | NAV_MAP_KEY(ImGuiKey_Space, ImGuiNavInput_Activate); |
| 3057 | NAV_MAP_KEY(ImGuiKey_Enter, ImGuiNavInput_Input); |
| 3058 | NAV_MAP_KEY(ImGuiKey_Escape, ImGuiNavInput_Cancel); |
| 3059 | NAV_MAP_KEY(ImGuiKey_LeftArrow, ImGuiNavInput_KeyLeft_); |
| 3060 | NAV_MAP_KEY(ImGuiKey_RightArrow, ImGuiNavInput_KeyRight_); |
| 3061 | NAV_MAP_KEY(ImGuiKey_UpArrow, ImGuiNavInput_KeyUp_); |
| 3062 | NAV_MAP_KEY(ImGuiKey_DownArrow, ImGuiNavInput_KeyDown_); |
| 3063 | if (g.IO.KeyCtrl) g.IO.NavInputs[ImGuiNavInput_TweakSlow] = 1.0f; |
| 3064 | if (g.IO.KeyShift) g.IO.NavInputs[ImGuiNavInput_TweakFast] = 1.0f; |
| 3065 | if (g.IO.KeyAlt) g.IO.NavInputs[ImGuiNavInput_KeyMenu_] = 1.0f; |
| 3066 | #undef NAV_MAP_KEY |
| 3067 | } |
| 3068 | |
| 3069 | memcpy(g.IO.NavInputsDownDurationPrev, g.IO.NavInputsDownDuration, sizeof(g.IO.NavInputsDownDuration)); |
| 3070 | for (int i = 0; i < IM_ARRAYSIZE(g.IO.NavInputs); i++) |
| 3071 | g.IO.NavInputsDownDuration[i] = (g.IO.NavInputs[i] > 0.0f) ? (g.IO.NavInputsDownDuration[i] < 0.0f ? 0.0f : g.IO.NavInputsDownDuration[i] + g.IO.DeltaTime) : -1.0f; |
| 3072 | |
| 3073 | // Process navigation init request (select first/default focus) |
| 3074 | if (g.NavInitResultId != 0 && (!g.NavDisableHighlight || g.NavInitRequestFromMove)) |
| 3075 | { |
| 3076 | // Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called) |
| 3077 | IM_ASSERT(g.NavWindow); |
| 3078 | if (g.NavInitRequestFromMove) |
| 3079 | SetNavIDAndMoveMouse(g.NavInitResultId, g.NavLayer, g.NavInitResultRectRel); |
| 3080 | else |
| 3081 | SetNavID(g.NavInitResultId, g.NavLayer); |
| 3082 | g.NavWindow->NavRectRel[g.NavLayer] = g.NavInitResultRectRel; |
| 3083 | } |
| 3084 | g.NavInitRequest = false; |
| 3085 | g.NavInitRequestFromMove = false; |
| 3086 | g.NavInitResultId = 0; |
| 3087 | g.NavJustMovedToId = 0; |
| 3088 | |
| 3089 | // Process navigation move request |
| 3090 | if (g.NavMoveRequest && (g.NavMoveResultLocal.ID != 0 || g.NavMoveResultOther.ID != 0)) |
| 3091 | { |
| 3092 | // Select which result to use |
| 3093 | ImGuiNavMoveResult* result = (g.NavMoveResultLocal.ID != 0) ? &g.NavMoveResultLocal : &g.NavMoveResultOther; |
| 3094 | if (g.NavMoveResultOther.ID != 0 && g.NavMoveResultOther.Window->ParentWindow == g.NavWindow) // Maybe entering a flattened child? In this case solve the tie using the regular scoring rules |
| 3095 | if ((g.NavMoveResultOther.DistBox < g.NavMoveResultLocal.DistBox) || (g.NavMoveResultOther.DistBox == g.NavMoveResultLocal.DistBox && g.NavMoveResultOther.DistCenter < g.NavMoveResultLocal.DistCenter)) |
| 3096 | result = &g.NavMoveResultOther; |
| 3097 | |
| 3098 | IM_ASSERT(g.NavWindow && result->Window); |
nothing calls this directly
no test coverage detected