Hi all,
I'd need some advice on how to implement a graphical list.
The (linear) list consists of different elements, that should be user drawn according to the contents. My first attempt was to use a scrollbox and just dynamically place panels with subcontrols. That worked well for small lists, but with more and more items, things got slow. I think the bottleneck is the scrollbox that triggeres a redraw of all elements once a control was removed or added. I'm now abandoning that approach and only want to draw what is actually visible on the screen. TDrawGrid seemed suitable for that and a first test was promising, but scrolling is quite odd, it seems that the scrolling is connected to the selected cell, while I just want to scroll the view and no selection. Also dragging the scrollbar doesn't immediately update the view.
As the functionality that I need is not too much I think about programming such a component from scratch (If there is not a recommendation for a suitable control).
And I wonder what would be the best way to do.
Requirements:
- The control should provide a handler/callback for each item like the DrawGrid providing a Canvas, on which can be drawn.
- Random dimensions for each element, but always one item below another
- Horizontal scrolling if it doesn't fit on the window
- Flicker-free
- Smooth pixel-wise scrolling (lower priority)
- No internal data, just a pointer for user data in each item could be enough
- Mouse control, handlers for clicks, double clicks
My basic idea is to use a TCustomControl containing two scrollbars and copying the user drawn canvas to the correct positions according to the scrollbars. Would it be better to use a Canvas for each visible item, so when a new item becomes visible only the new item has to be redrawn and the existing ones could just be copied from the buffers, or should every element just be redrawn to avoid cache issues?
Also what kind of canvas would be advisable regarding speed, a TBitmap, a TBGRABitmap? The first one could mean (slow) API-calls of the operating system, but could have faster copy mechanisms (Just guesses).
Another possibility would be to dynamically place a seperate control for each visible item and move them around according to the scrollbars. The hope would be that moving is efficiently handled by the OS on the GPU and wouldn't involve manual redrawing or data copying using the CPU. But I'm not sure there either. It also could mean a lot of API-calls and even redraws.
Or are there other approaches? I'm happy for any comments.
Thanks!