Closed tpstevens closed 1 month ago
Hi! Have you looked at the infinite_scroll dnd example? It should be pretty similar to the virtual_list, since internally infinite_scroll is just a wrapper around a virtual_list? If that doesn't help I can try to create a virtual_list example tomorrow.
Aha -- I missed that because I only searched for virtual list. I see what I'm doing wrong now. Thanks very much!
Hello! I'm trying to combine the virtual list with a drag-and-drop list, and I'm seeing some strange behavior with rendering and dragging. I think it comes down to the way that I'm calculating the number of items to render within
dnd::show()
, but I'm not sure if I'm approaching the problem correctly.I've started with the virtual list example and refactored out the drawing to be able to draw dnd elements. Here's the overall structure:
And here's how I'm wrapping the dnd list inside the virtual list:
As written above, this code draws every single element each time, as the
layout
closure passed tovirtual_list::ui_custom_layout
draws every single item. I've tried a number of different methods to calculate how many elements I should render based on the available space, but I haven't been able to account for the scroll area's current offset and the virtual list's overscan. It's pretty easy to get the maximum vertical area (as that can be calculated with the central panel'sui.available_height()
or cached from the result ofScrollArea::vertical().show()
), but it's not clear to me how to take into account the scroll area's current offset.Ignoring that issue and rendering a fixed number of items, I haven't been able to drag an item cleanly across dnd "boundaries". For example, if I render 10 item in
dnd::show()
, the virtual list will sometimes call thelayout
closure with a start_index of 0 and a start_index of 10 (which makes sense). If I drag an item within indices 0 to 9 or 10 to 19, the other items appear to move out of the way as the item is dragged through them and the list is properly updated upon release. If I drag an item from index 2 to index 14, it behaves properly until it passes index 9, and then it appears to float over the next elements instead of them moving out of the way. I'm not sure how to handle this, because from the perspective of each call todnd::show()
, the iterator at the start of the drag is different than the iterator at the end (if the layout closure passed tovirtual_list::show()
is called multiple times).In summary, my questions are:
dnd::show()
?dnd::show()?
Thanks very much! Once I get this sorted out, I'm happy to clean it up and submit it as a PR for a virtual list + dnd example.