Recommended / best practice for virtual list of unlimited size


#1

I have a video/security app that generates a “visual log” - timestamped lines where a “line” is either a line of text, or an image followed by text. Each “log line” is one application event, and over time there could be tens of thousands of log lines.

The goal is to have a vertically scrolling window providing users with a view of these “visual log” lines. The text is always the same height, but each image could be a different height, and there is not any order to when a “log line” is an image with text or just text.

It looks like there is a ListBox() signature that accepts an “items_getter” callback. It also has a comment in the code suggesting one implement their own ListBox() for cases where the height of each line may vary. I have not found any examples of using this ListBox() signature that accepts a callback; is there an example? In that ListBox() signature:

bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items)

It looks like the “void * data” parameter is my own data pointer that is ultimately passed to the callback. It also looks like the total number of items as well as the height of all those items is used by the implementation of this ListBox() signature. How would one go about implementing a similar ListBox() with items_getter callback, but supports variable height lines?

Reading the comments around ImGuiListClipper, that starts out saying the list should be evenly spaced items (meaning vertical spacing, right?) and random access to the list items. In my case, the list items are in a database, and only after retrieval from the database is any individual timestamp’s content known.

Sorry for the range of questions. They all surround this basic idea of how to implement a scrolling control for viewing a potentially very large number of items of unknown height. Any guide or suggestions are appreciated.


#2

Hello, it is fine to post it on the github repo.