Apply result from previous frame navigation directional move request. Always called from NavUpdate()
| 11713 | |
| 11714 | // Apply result from previous frame navigation directional move request. Always called from NavUpdate() |
| 11715 | void ImGui::NavMoveRequestApplyResult() |
| 11716 | { |
| 11717 | ImGuiContext& g = *GImGui; |
| 11718 | #if IMGUI_DEBUG_NAV_SCORING |
| 11719 | if (g.NavMoveFlags & ImGuiNavMoveFlags_DebugNoResult) // [DEBUG] Scoring all items in NavWindow at all times |
| 11720 | return; |
| 11721 | #endif |
| 11722 | |
| 11723 | // Select which result to use |
| 11724 | ImGuiNavItemData* result = (g.NavMoveResultLocal.ID != 0) ? &g.NavMoveResultLocal : (g.NavMoveResultOther.ID != 0) ? &g.NavMoveResultOther : NULL; |
| 11725 | |
| 11726 | // Tabbing forward wrap |
| 11727 | if ((g.NavMoveFlags & ImGuiNavMoveFlags_IsTabbing) && result == NULL) |
| 11728 | if ((g.NavTabbingCounter == 1 || g.NavTabbingDir == 0) && g.NavTabbingResultFirst.ID) |
| 11729 | result = &g.NavTabbingResultFirst; |
| 11730 | |
| 11731 | // In a situation when there are no results but NavId != 0, re-enable the Navigation highlight (because g.NavId is not considered as a possible result) |
| 11732 | const ImGuiAxis axis = (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? ImGuiAxis_Y : ImGuiAxis_X; |
| 11733 | if (result == NULL) |
| 11734 | { |
| 11735 | if (g.NavMoveFlags & ImGuiNavMoveFlags_IsTabbing) |
| 11736 | g.NavMoveFlags |= ImGuiNavMoveFlags_NoSetNavHighlight; |
| 11737 | if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_NoSetNavHighlight) == 0) |
| 11738 | NavRestoreHighlightAfterMove(); |
| 11739 | NavClearPreferredPosForAxis(axis); // On a failed move, clear preferred pos for this axis. |
| 11740 | IMGUI_DEBUG_LOG_NAV("[nav] NavMoveSubmitted but not led to a result!\n"); |
| 11741 | return; |
| 11742 | } |
| 11743 | |
| 11744 | // PageUp/PageDown behavior first jumps to the bottom/top mostly visible item, _otherwise_ use the result from the previous/next page. |
| 11745 | if (g.NavMoveFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) |
| 11746 | if (g.NavMoveResultLocalVisible.ID != 0 && g.NavMoveResultLocalVisible.ID != g.NavId) |
| 11747 | result = &g.NavMoveResultLocalVisible; |
| 11748 | |
| 11749 | // Maybe entering a flattened child from the outside? In this case solve the tie using the regular scoring rules. |
| 11750 | if (result != &g.NavMoveResultOther && g.NavMoveResultOther.ID != 0 && g.NavMoveResultOther.Window->ParentWindow == g.NavWindow) |
| 11751 | if ((g.NavMoveResultOther.DistBox < result->DistBox) || (g.NavMoveResultOther.DistBox == result->DistBox && g.NavMoveResultOther.DistCenter < result->DistCenter)) |
| 11752 | result = &g.NavMoveResultOther; |
| 11753 | IM_ASSERT(g.NavWindow && result->Window); |
| 11754 | |
| 11755 | // Scroll to keep newly navigated item fully into view. |
| 11756 | if (g.NavLayer == ImGuiNavLayer_Main) |
| 11757 | { |
| 11758 | ImRect rect_abs = WindowRectRelToAbs(result->Window, result->RectRel); |
| 11759 | ScrollToRectEx(result->Window, rect_abs, g.NavMoveScrollFlags); |
| 11760 | |
| 11761 | if (g.NavMoveFlags & ImGuiNavMoveFlags_ScrollToEdgeY) |
| 11762 | { |
| 11763 | // FIXME: Should remove this? Or make more precise: use ScrollToRectEx() with edge? |
| 11764 | float scroll_target = (g.NavMoveDir == ImGuiDir_Up) ? result->Window->ScrollMax.y : 0.0f; |
| 11765 | SetScrollY(result->Window, scroll_target); |
| 11766 | } |
| 11767 | } |
| 11768 | |
| 11769 | if (g.NavWindow != result->Window) |
| 11770 | { |
| 11771 | IMGUI_DEBUG_LOG_FOCUS("[focus] NavMoveRequest: SetNavWindow(\"%s\")\n", result->Window->Name); |
| 11772 | g.NavWindow = result->Window; |
nothing calls this directly
no test coverage detected