I'm a bit out of ideas here. I want a very simple thing: to be able to select a given GtkListBox
row programmatically and then scroll the list box (which is wrapped in a ScrolledWindow
and a Viewport
).
Selecting a row is trivial (my code is Go & gotk3, but that's not so important):
listBox.SelectRow(row)
But scrolling to the row proved to be a real challenge. Whatever I tried, I failed:
- I tried to focus the row, but it helped nothing
- I tried to figure out the row's Y-coordinate using
gtk_widget_translate_coordinates()
, but it returns -1 for any row - Perhaps I can find out which row is at the top and the bottom of the list box and use that to scroll the
ScrolledWindow
but I can't figure out how to do that.
Update: I've tried what's proposed here: Manually scroll to a child in a Gtk.ScrolledWindow, but it didn't work as still no scrolling occurred:
listbox.SelectRow(rowToSelect)
listbox.SetFocusVAdjustment(listbox.GetAdjustment())
if rowToSelect != nil {
rowToSelect.GrabFocus()
}
I also tried the same with rowToSelect
's child using the code below, to no avail:
if c, err := rowToSelect.GetChild(); err == nil {
c.GrabFocus()
}