slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 566 forks source link

Selecting a new item in StandardListView by keyboard does not trigger scrolling #2209

Closed medhefgo closed 1 year ago

medhefgo commented 1 year ago

Items inside of a StandardListView can be selected by keyboard arrow keys, but doing so will not scroll if the newly selected item is outside the current viewport. This can be easily tested in the widget gallery by selecting an item and then using down arrow (several times) to change the selection to an item in the bottom of the list.

tronical commented 1 year ago

Indeed. I suppose we need to do something like we do in TextEdit when the cursor position changes. But where we know the cursor y coordinate from the native code, while here we'd need to get it out of a repeater's item.

I wonder if creative minds @ogoffart and @FloVanGH have any idea how to do this in a clever way? :)

ogoffart commented 1 year ago

Yeah, that's not trivial to implement. I guess one way would be to add a function ensure-visible(row) to the ListView, that would be lowered to native code .

Without that, it could be implemented for ListView that have constant item height by playing with the content-y in the keyboard binding

medhefgo commented 1 year ago

I guess one way would be to add a function ensure-visible(row) to the ListView, that would be lowered to native code .

Make that Flickable, please.

Without that, it could be implemented for ListView that have constant item height by playing with the content-y in the keyboard binding

I did that. It's feasible, but obviously doesn't work when you have a flickable with different item heights. It would be really nice if one could create properties that can bind to components. Then this would be far simpler to accomplish:

FloVanGH commented 1 year ago

@ogoffart @tronical I have implement that feature for the auto completion on my tiling desktop project. I could check it next week.

FloVanGH commented 1 year ago

PR: https://github.com/slint-ui/slint/pull/2246