| 1780 | } |
| 1781 | |
| 1782 | bool ImGuiListClipper::Step() |
| 1783 | { |
| 1784 | if (ItemsCount == 0 || ImGui::GetCurrentWindowRead()->SkipItems) |
| 1785 | { |
| 1786 | ItemsCount = -1; |
| 1787 | return false; |
| 1788 | } |
| 1789 | if (StepNo == 0) // Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height. |
| 1790 | { |
| 1791 | DisplayStart = 0; |
| 1792 | DisplayEnd = 1; |
| 1793 | StartPosY = ImGui::GetCursorPosY(); |
| 1794 | StepNo = 1; |
| 1795 | return true; |
| 1796 | } |
| 1797 | if (StepNo == 1) // Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element. |
| 1798 | { |
| 1799 | if (ItemsCount == 1) { ItemsCount = -1; return false; } |
| 1800 | float items_height = ImGui::GetCursorPosY() - StartPosY; |
| 1801 | IM_ASSERT(items_height > 0.0f); // If this triggers, it means Item 0 hasn't moved the cursor vertically |
| 1802 | Begin(ItemsCount-1, items_height); |
| 1803 | DisplayStart++; |
| 1804 | DisplayEnd++; |
| 1805 | StepNo = 3; |
| 1806 | return true; |
| 1807 | } |
| 1808 | if (StepNo == 2) // Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user still call Step(). Does nothing and switch to Step 3. |
| 1809 | { |
| 1810 | IM_ASSERT(DisplayStart >= 0 && DisplayEnd >= 0); |
| 1811 | StepNo = 3; |
| 1812 | return true; |
| 1813 | } |
| 1814 | if (StepNo == 3) // Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop. |
| 1815 | End(); |
| 1816 | return false; |
| 1817 | } |
| 1818 | |
| 1819 | //----------------------------------------------------------------------------- |
| 1820 | // ImGuiWindow |
no test coverage detected