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

Method CalcListClipping

tutorials/common/imgui/imgui.cpp:2570–2611  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

2568// This legacy API is not ideal because it assumes we will return a single contiguous rectangle.
2569// Prefer using ImGuiListClipper which can returns non-contiguous ranges.
2570void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end)
2571{
2572 ImGuiContext& g = *GImGui;
2573 ImGuiWindow* window = g.CurrentWindow;
2574 if (g.LogEnabled)
2575 {
2576 // If logging is active, do not perform any clipping
2577 *out_items_display_start = 0;
2578 *out_items_display_end = items_count;
2579 return;
2580 }
2581 if (GetSkipItemForListClipping())
2582 {
2583 *out_items_display_start = *out_items_display_end = 0;
2584 return;
2585 }
2586
2587 // We create the union of the ClipRect and the scoring rect which at worst should be 1 page away from ClipRect
2588 // We don't include g.NavId's rectangle in there (unless g.NavJustMovedToId is set) because the rectangle enlargement can get costly.
2589 ImRect rect = window->ClipRect;
2590 if (g.NavMoveScoringItems)
2591 rect.Add(g.NavScoringNoClipRect);
2592 if (g.NavJustMovedToId && window->NavLastIds[0] == g.NavJustMovedToId)
2593 rect.Add(WindowRectRelToAbs(window, window->NavRectRel[0])); // Could store and use NavJustMovedToRectRel
2594
2595 const ImVec2 pos = window->DC.CursorPos;
2596 int start = (int)((rect.Min.y - pos.y) / items_height);
2597 int end = (int)((rect.Max.y - pos.y) / items_height);
2598
2599 // When performing a navigation request, ensure we have one item extra in the direction we are moving to
2600 // FIXME: Verify this works with tabbing
2601 const bool is_nav_request = (g.NavMoveScoringItems && g.NavWindow && g.NavWindow->RootWindowForNav == window->RootWindowForNav);
2602 if (is_nav_request && g.NavMoveClipDir == ImGuiDir_Up)
2603 start--;
2604 if (is_nav_request && g.NavMoveClipDir == ImGuiDir_Down)
2605 end++;
2606
2607 start = ImClamp(start, 0, items_count);
2608 end = ImClamp(end + 1, start, items_count);
2609 *out_items_display_start = start;
2610 *out_items_display_end = end;
2611}
2612#endif
2613
2614static void ImGuiListClipper_SortAndFuseRanges(ImVector<ImGuiListClipperRange>& ranges, int offset = 0)

Callers

nothing calls this directly

Calls 4

WindowRectRelToAbsFunction · 0.85
ImClampFunction · 0.85
AddMethod · 0.80

Tested by

no test coverage detected