ListBox scroll on changing element

Hello, my problem now is program is changing a selected element of a ListBox and this works, but the visual interface doesn’t scroll to that element. I couldn’t find an appropriate function/argument to adjust the displayed region to include the selected item. Is this possible?
Thank you!

you can use ImGui::SetScrollHere(ratio)

Hi, I found that SetScrollHere is deprecated so I tried SetScrollHereY(0.5) right after a listbox but nothing happened. Is there anything I’m missing here?

Also header says it’s a Window scrolling function, not sure if it should work with widgets…

Check the demo to understand how those functions are used.

You probably want to write your item submitting loop and call SetScrollHere() on the selected item, based on a flag (e.g. selection was changed). If you do it every frame you will block user from scrolling.

Not sure what is item submitting loop?

It’s still possible to scroll, probably because it affects window but not ListBox.

In the demo I only see it used together with BeginChild() / EndChild() - does it mean I should “unwrap” ListBox somehow to put this code inside?

Yes, use ListBoxHeader/ListBoxFooter and submit the Selectable items yourself.