Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved ImGuiListClipper helper #661

Closed
ocornut opened this issue May 15, 2016 · 1 comment
Closed

Improved ImGuiListClipper helper #661

ocornut opened this issue May 15, 2016 · 1 comment
Labels

Comments

@ocornut
Copy link
Owner

ocornut commented May 15, 2016

Many times using the clipper helper I thought that it needed to be improved. Since the requirement of passing item height manually is rather error-prone.

Also issues e.g. #660

Currently typically use is:

ImGuiListClipper clipper(lines, ImGui::GetTextLineHeightWithSpacing());
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
    ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);
clipper.End();

And improved version could be:

ImGuiListClipper clipper(lines);
while (clipper.Step())
    for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
        ImGui::Text("%i The quick brown fox jumps over the lazy dog\n", i);

(unsure about Step function name - any suggestion?)

The idea is that:

  • The first time Step() function is called would return true, set DisplayStart to 0 and DisplayEnd to 1
  • This first loop would be used to calculate the item height
  • The second time Step() function is called it would return true, set DisplayStart/DisplayEnd to actual values based on clipping.
  • The third time Step() function is called it would return false and call "End" which is the final positional seeking.

Interesting this improvement seems possible without breaking the current code.
I would make the second parameter of the construction -1 by default.

@ocornut
Copy link
Owner Author

ocornut commented May 16, 2016

Done.
7a28f5b
28b0919

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant