xilem icon indicating copy to clipboard operation
xilem copied to clipboard

Adding, deleting or updating rows of a list

Open edko99 opened this issue 2 years ago • 2 comments

Is it possible to add functionality to send a signal to a list view that the underlying data has changed, like for example that some rows were added, deleted, or changed? In addition to the straightforward use, this would allow trees to be implemented on top of lists: deleting rows can be used when collapsing, and inserting rows when expanding.

edko99 avatar Jan 10 '23 00:01 edko99

Sorry for the slow response. I hope i understand the question correctly. The think you want to achieve is already possible. You can create a Tree view which uses a List widget and only rebuilds the views, which are currently expanded. If you add a node to the tree datastructure, your tree view is rebuild automatically. But the way lists work is currently in flux. We will probably merge the List view and the LinearLayout view, and allow variable length ViewSequences instead. Here you can find a discussion about it. One last note. Doing what you proposed is fine for a simple Tree view, but we probably want a dedicated Tree view and widget, since otherwise we would have to put functionality specific to trees into the LinearLayout widget and make it possible for ViewSequences to interact with it.

xarvic avatar Mar 07 '23 17:03 xarvic

There's a lot more to say about this, and I will address it in a future blog post (this is actually next in my queue and I have a draft, but am seriously overloaded).

In the "small" case, indeed you can represent the list as a Vec (or some other similar sequence type), and then have a corresponding view that diffs it against the previous value. This involves making the ViewSequence trait a little more powerful, specifically able to handle variable numbers of items in the sequence, and also containers better at tracking their children so they can handle insert, remove, and reorder.

However, that approach will lead to performance problems as the number of items scales. For the "big" case you need virtualization so you're not touching all the list items every update. One approach is Dongdong's [virtual list] in floem. However, the direction I'm going is to use a sequence with sparse diffing, as in my RustLab 2020 talk. I believe this will combine excellent ergonomics with excellent performance, but is pretty far from being implemented at this point.

Sorry I can't give a more precise roadmap at this point.

raphlinus avatar Mar 07 '23 17:03 raphlinus