bczsalba / pytermgui

Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!
https://ptg.bczsalba.com
MIT License
2.25k stars 56 forks source link

[REQUEST] Browsing between selectables does not trigger scroll #148

Open kadaxo opened 3 months ago

kadaxo commented 3 months ago

Is your feature request related to a problem? Please describe. Browsing between selectables should trigger scroll to always show where the selectable is.

Describe the solution you'd like Just compare selected_index to scroll_offset to check if the scrollable is in visible area, otherwise scroll the diff amount.

Describe alternatives you've considered Tried to implement myself by overriding select() and handle_key(), couldn't make it work, scroll is irresponsive.

Is this feature present in other TUI products? I don't know.

Additional context Can be reproduced like this : Window -> Container -> [Button, Button, Button ...]

bczsalba commented 1 month ago

I think the problem here is that the selection is handled first at the higher level (e.g. Window), which thinks the Container itself is visible so it just moves on. The container doesn't have any awareness that its content is cut off IIRC, so it can't react appropriately. Not sure if an easy implementation here is possible, but it already is a bit more complicated than your (helpful!) algorithm, as widgets might be different heights.

FWIW this should work when inserted at the end of select, but doesn't for the aforementioned reasons.

if self.selected is not None and not self.contains(self.selected.pos):
    self.scroll(self.selected.pos[1] - (self.pos[1] + self._scroll_offset))