Legacy helper to calculate coarse clipping of large list of evenly sized items. This legacy API is not ideal because it assumes we will return a single contiguous rectangle. Prefer using ImGuiListClipper which can returns non-contiguous ranges.
| 2690 | // This legacy API is not ideal because it assumes we will return a single contiguous rectangle. |
| 2691 | // Prefer using ImGuiListClipper which can returns non-contiguous ranges. |
| 2692 | void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end) |
| 2693 | { |
| 2694 | ImGuiContext& g = *GImGui; |
| 2695 | ImGuiWindow* window = g.CurrentWindow; |
| 2696 | if (g.LogEnabled) |
| 2697 | { |
| 2698 | // If logging is active, do not perform any clipping |
| 2699 | *out_items_display_start = 0; |
| 2700 | *out_items_display_end = items_count; |
| 2701 | return; |
| 2702 | } |
| 2703 | if (GetSkipItemForListClipping()) |
| 2704 | { |
| 2705 | *out_items_display_start = *out_items_display_end = 0; |
| 2706 | return; |
| 2707 | } |
| 2708 | |
| 2709 | // We create the union of the ClipRect and the scoring rect which at worst should be 1 page away from ClipRect |
| 2710 | // We don't include g.NavId's rectangle in there (unless g.NavJustMovedToId is set) because the rectangle enlargement can get costly. |
| 2711 | ImRect rect = window->ClipRect; |
| 2712 | if (g.NavMoveScoringItems) |
| 2713 | rect.Add(g.NavScoringNoClipRect); |
| 2714 | if (g.NavJustMovedToId && window->NavLastIds[0] == g.NavJustMovedToId) |
| 2715 | rect.Add(WindowRectRelToAbs(window, window->NavRectRel[0])); // Could store and use NavJustMovedToRectRel |
| 2716 | |
| 2717 | const ImVec2 pos = window->DC.CursorPos; |
| 2718 | int start = (int)((rect.Min.y - pos.y) / items_height); |
| 2719 | int end = (int)((rect.Max.y - pos.y) / items_height); |
| 2720 | |
| 2721 | // When performing a navigation request, ensure we have one item extra in the direction we are moving to |
| 2722 | // FIXME: Verify this works with tabbing |
| 2723 | const bool is_nav_request = (g.NavMoveScoringItems && g.NavWindow && g.NavWindow->RootWindowForNav == window->RootWindowForNav); |
| 2724 | if (is_nav_request && g.NavMoveClipDir == ImGuiDir_Up) |
| 2725 | start--; |
| 2726 | if (is_nav_request && g.NavMoveClipDir == ImGuiDir_Down) |
| 2727 | end++; |
| 2728 | |
| 2729 | start = ImClamp(start, 0, items_count); |
| 2730 | end = ImClamp(end + 1, start, items_count); |
| 2731 | *out_items_display_start = start; |
| 2732 | *out_items_display_end = end; |
| 2733 | } |
| 2734 | #endif |
| 2735 | |
| 2736 | static void ImGuiListClipper_SortAndFuseRanges(ImVector<ImGuiListClipperRange>& ranges, int offset = 0) |
nothing calls this directly
no test coverage detected