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.
| 2630 | // This legacy API is not ideal because it assumes we will return a single contiguous rectangle. |
| 2631 | // Prefer using ImGuiListClipper which can returns non-contiguous ranges. |
| 2632 | void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end) |
| 2633 | { |
| 2634 | ImGuiContext& g = *GImGui; |
| 2635 | ImGuiWindow* window = g.CurrentWindow; |
| 2636 | if (g.LogEnabled) |
| 2637 | { |
| 2638 | // If logging is active, do not perform any clipping |
| 2639 | *out_items_display_start = 0; |
| 2640 | *out_items_display_end = items_count; |
| 2641 | return; |
| 2642 | } |
| 2643 | if (GetSkipItemForListClipping()) |
| 2644 | { |
| 2645 | *out_items_display_start = *out_items_display_end = 0; |
| 2646 | return; |
| 2647 | } |
| 2648 | |
| 2649 | // We create the union of the ClipRect and the scoring rect which at worst should be 1 page away from ClipRect |
| 2650 | // We don't include g.NavId's rectangle in there (unless g.NavJustMovedToId is set) because the rectangle enlargement can get costly. |
| 2651 | ImRect rect = window->ClipRect; |
| 2652 | if (g.NavMoveScoringItems) |
| 2653 | rect.Add(g.NavScoringNoClipRect); |
| 2654 | if (g.NavJustMovedToId && window->NavLastIds[0] == g.NavJustMovedToId) |
| 2655 | rect.Add(WindowRectRelToAbs(window, window->NavRectRel[0])); // Could store and use NavJustMovedToRectRel |
| 2656 | |
| 2657 | const ImVec2 pos = window->DC.CursorPos; |
| 2658 | int start = (int)((rect.Min.y - pos.y) / items_height); |
| 2659 | int end = (int)((rect.Max.y - pos.y) / items_height); |
| 2660 | |
| 2661 | // When performing a navigation request, ensure we have one item extra in the direction we are moving to |
| 2662 | // FIXME: Verify this works with tabbing |
| 2663 | const bool is_nav_request = (g.NavMoveScoringItems && g.NavWindow && g.NavWindow->RootWindowForNav == window->RootWindowForNav); |
| 2664 | if (is_nav_request && g.NavMoveClipDir == ImGuiDir_Up) |
| 2665 | start--; |
| 2666 | if (is_nav_request && g.NavMoveClipDir == ImGuiDir_Down) |
| 2667 | end++; |
| 2668 | |
| 2669 | start = ImClamp(start, 0, items_count); |
| 2670 | end = ImClamp(end + 1, start, items_count); |
| 2671 | *out_items_display_start = start; |
| 2672 | *out_items_display_end = end; |
| 2673 | } |
| 2674 | #endif |
| 2675 | |
| 2676 | static void ImGuiListClipper_SortAndFuseRanges(ImVector<ImGuiListClipperRange>& ranges, int offset = 0) |
nothing calls this directly
no test coverage detected