| 2311 | } |
| 2312 | |
| 2313 | bool ImGuiListClipper::Step() |
| 2314 | { |
| 2315 | ImGuiContext& g = *GImGui; |
| 2316 | ImGuiWindow* window = g.CurrentWindow; |
| 2317 | |
| 2318 | ImGuiTable* table = g.CurrentTable; |
| 2319 | if (table && table->IsInsideRow) |
| 2320 | ImGui::TableEndRow(table); |
| 2321 | |
| 2322 | // No items |
| 2323 | if (ItemsCount == 0 || GetSkipItemForListClipping()) |
| 2324 | { |
| 2325 | End(); |
| 2326 | return false; |
| 2327 | } |
| 2328 | |
| 2329 | // Step 0: Let you process the first element (regardless of it being visible or not, so we can measure the element height) |
| 2330 | if (StepNo == 0) |
| 2331 | { |
| 2332 | // While we are in frozen row state, keep displaying items one by one, unclipped |
| 2333 | // FIXME: Could be stored as a table-agnostic state. |
| 2334 | if (table != NULL && !table->IsUnfrozenRows) |
| 2335 | { |
| 2336 | DisplayStart = ItemsFrozen; |
| 2337 | DisplayEnd = ItemsFrozen + 1; |
| 2338 | ItemsFrozen++; |
| 2339 | return true; |
| 2340 | } |
| 2341 | |
| 2342 | StartPosY = window->DC.CursorPos.y; |
| 2343 | if (ItemsHeight <= 0.0f) |
| 2344 | { |
| 2345 | // Submit the first item so we can measure its height (generally it is 0..1) |
| 2346 | DisplayStart = ItemsFrozen; |
| 2347 | DisplayEnd = ItemsFrozen + 1; |
| 2348 | StepNo = 1; |
| 2349 | return true; |
| 2350 | } |
| 2351 | |
| 2352 | // Already has item height (given by user in Begin): skip to calculating step |
| 2353 | DisplayStart = DisplayEnd; |
| 2354 | StepNo = 2; |
| 2355 | } |
| 2356 | |
| 2357 | // Step 1: the clipper infer height from first element |
| 2358 | if (StepNo == 1) |
| 2359 | { |
| 2360 | IM_ASSERT(ItemsHeight <= 0.0f); |
| 2361 | if (table) |
| 2362 | { |
| 2363 | const float pos_y1 = table->RowPosY1; // Using this instead of StartPosY to handle clipper straddling the frozen row |
| 2364 | const float pos_y2 = table->RowPosY2; // Using this instead of CursorPos.y to take account of tallest cell. |
| 2365 | ItemsHeight = pos_y2 - pos_y1; |
| 2366 | window->DC.CursorPos.y = pos_y2; |
| 2367 | } |
| 2368 | else |
| 2369 | { |
| 2370 | ItemsHeight = window->DC.CursorPos.y - StartPosY; |
no test coverage detected