peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.62k stars 237 forks source link

Create autoscroll for listbox #318

Open catarium opened 3 years ago

catarium commented 3 years ago

Listbox autoscrolling if scrollbar is at the bottom. Example: https://user-images.githubusercontent.com/60063501/120595827-aa149900-c44b-11eb-9b66-c90f57678208.mp4

peterbrittain commented 3 years ago

Hi. It's not clear what you're asking for...

Looking at your video, you are clearly updating the options of a ListBox (to add a new line). When you do that, asciimatics will try to find the existing selection in the new list of options and scroll to make that visible, which is what appears to be happening here.

Can you explain what you want to change?

catarium commented 3 years ago

@peterbrittain

Ok, I'll try explain my idea by code, because my eng not good.

if ListBox.value == ListBox.options[-1][1]:
    ListBox.options = new_options
    ListBox.value = new_options[-1][1] # scroll to bottom of listbox
else:
    ListBox.options = new_options
peterbrittain commented 3 years ago

Ok! Got it. Thanks.

It seems to me that this code is easy to write if anyone needs it, so I'm not sure it warrants adding to the base package. Looking at equivalent GUI systems, it's pretty common that you have to write something similar to that. For example, see https://www.csharp-examples.net/autoscroll/

But maybe it would be easier to write if the selected index was exposed as a property?

catarium commented 3 years ago

May create a flag that will execute such code

ListBox.autoscroll = True

or

ListBox.set_autoscroll(True)