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

Are there anyway to mix textbox with dropdown list? #310

Closed jarodtang closed 3 years ago

jarodtang commented 3 years ago

Hi There,

I'm trying to implement a feature like, there's a drop down option to be selected from, while I'm typing texts in a text box? like following picture. image

Are there anyway to do it?

Regards, Jarod

peterbrittain commented 3 years ago

I assume you actually mean a single line Text widget rather than the multiline Textbox widget.

If so, the existing dropdown widget already supports a basic form of searching through the options when you type anything into the widget. Just select the dropdown and start typing the text for the option you want to select.

However, if what you really want is automatic suggestions for a free-form Text widget, there is no current support for this. It's possible to add this as a new type of widget (or possibly as another option on Text) using similar logic to the dropdown widget (but then dynamically changing the dropdown options).

Feels like it could be a good addition to the widgets, but I don't have enough time to add that in the near future. I'd be happy to help you add it, though.

jarodtang commented 3 years ago

Thanks for your reply. I was point to the "a free-form Text widget", I'll try to figure out a way to implement one.

peterbrittain commented 3 years ago

Cool. As I said before... I'd advise you to look at the way the dropdown widget works and use a similar mechanism for the automatic suggestions. The sneaky bit in the design is how it pops up a completely new Frame over the top of the existing one and then handles everything inside that new Frame.

You'd want to use a similar design, but leave the new Text field in that Frame enabled. Then instead of synching from the Listbox to the Text field, you'd want to repopulate the Listbox with options based on the current text of the Text field as it changes. Finally you probably need to ensure that any selection in the list box updates the Text field and moves the focus back to the Text field so that the user can carry on typing as needed.

Hope that helps. Feel free to drop me a line if you need more pointers.

peterbrittain commented 3 years ago

I'm assuming this was enough help, so now closing...