Infinite scroll ListBox

I have made a listview out of (gtk::ListBoxRow) that could show the biggest of data efficiently starting from the example (gtk4-rs/examples/list_box_model) using gio::ListModel. I have a problem that I would like I know how to solve in a better way

I take a slice of the data and show it as boxes, once the user scrolls down to the end of the list I delete the top half of the boxes and add the same amount of deleted data as boxes to the end of the list.

The problem is that when I do that I use items_changed() on the model and that changes the current view position, so the user has to scroll back again to the end of the list. I have tried using ScrollWindow::Adjustment::set_value() before or after using items_changed() and it didn’t help in changing the view position when it is at the bottom of the list.

Other side effects of this method are that items are deleted, so selection management has to also be done manually.

My goal is to be able to view and edit infinitely sized data efficiently and smoothly. I have done most of it, but the view position is my biggest issue now.

I would love if this gets integrated into GTK4

Any tip would help, thank you

1 Like

Hi,

At this point, you could try to:

  • hide the default scrollbar by setting the Gtk.ScrolledWindow:vscrollbar-policy property to GTK_POLICY_EXTERNAL.
  • add your own GtkScrollbar+GtkAdjustment, that you can fully control, and update them when the scrolledwindow’s adjustment changes, and when you add/remove items to your list.

I’m not sure a GtkListBox is really suitable for this usecase. Its expected behavior may sometimes conflict with the infinite scrolling. You may want to implement your own GtkWidget subclass instead.