Tobias Weber wrote:
Hi,
being very new to GUI in general, I looked through the demo, but didn't find a container widget I liked. So I subclassed Panel, put a bunch of stuff in, and populated a ScrolledPanel (BoxSizer) with instances.
Works great. But with more than a hundred it gets slow and eats memory. I need up to 6000.
Cocoa has CollectionView, which is essentially ScrolledPanel and BoxSizer rolled into one plus a factory for your custom item class. It keps a few instances around, changes the data they display, and re-uses them on the other end to simulate scrolling through a huge list. I think wx calls this virtual.
I don't feel confident to clone this. Are there building blocks? Or an easy solution I overlooked?
One way to approach it is to do something like this:
* Use a plain panel instead of a scrolled panel
Create enough of the subpanels to fill the panel, and add a wx.ScrollBar on the side.
* if not already then disconnect the data to be displayed from your subpanels such that they do not depend on each other. In other words, the widgets should not be the in-memory storage place for the data, there should be just a loose coupling between them.
* When you get events from the scrollbar just adjust which of the data items each of the subpanels is displaying by changing the reference from the subpanel to the data item and refreshing.
In other words, instead of scrolling the widgets, you are "scrolling" which of the data items that the widgets are displaying.
···
--
Robin Dunn
Software Craftsman