Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kadaxo opened this issue Jun 16, 2024 · 1 comment
Open

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

kadaxo opened this issue Jun 16, 2024 · 1 comment
Labels
Enhancement New feature or request

Comments

@kadaxo
Copy link

kadaxo commented Jun 16, 2024

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 ...]

@kadaxo kadaxo added the Enhancement New feature or request label Jun 16, 2024
@bczsalba
Copy link
Owner

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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants