peterhinch / micropython-micro-gui

A lightweight MicroPython GUI library for display drivers based on framebuf, allows input via pushbuttons. See also micropython-touch.
MIT License
247 stars 37 forks source link

Question: Is there a way to dynamically update the elements listed in a Dropdown object? #32

Open evan-rasmussen opened 1 year ago

evan-rasmussen commented 1 year ago

Title pretty much explains it. I am trying to get it so the user can input a string that then needs to be added to the elements in a dropdown object. Is there a way to do this dynamically?

peterhinch commented 1 year ago

That is an interesting question, but I'm very short of time today so this answer is brief and might be described as an educated guess. You might like to experiment.

The dropdown instance has a bound variable .elements which holds the text values. When the user clicks on the dropdown, a listbox is instantiated here using those elements (see docs for listbox). So it might be possible to modify dropdown.elements at times when the dropdown is not open. See listbox docs for the two possible formats of .elements.

Troyhy commented 4 days ago

I had similar need and I have test implementation for listbox https://github.com/Troyhy/micropython-micro-gui/blob/ESP-Now/gui/widgets/listbox.py#L75-L97 but this is very rough on edges, I did not fully got the updating elements and scroll position right. Crashes if you update list of 0 elements

peterhinch commented 3 days ago

This is evidently worth doing. I'll investigate this, but it may be a few days before I get the opportunity