Latest Posts

Topic: Editable dropdown?

kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2551
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2024-02-26, 17:28

Is it possible to have an editable dropdown widget?

Wanted behavior of such an "dropdowneditbox":
A dropdown shows initially nothing. If one enters a (valid) text into the dropdowneditbox the list of dropdown-entries will get an an additional entry of the just entered text. So the more text get entered the more entries the dropdown will have. Preferably without double entries, that is: If the entered text is always in the dropdown entry-list, it will not be added again. Somehow a self-learning widget.

I came across this idea by using the "Copy area" addon: Often i needed values (x- and y-coordinates) which were just used some time ago. In the current implementation you have to

  1. Recognize the value
  2. Fiddle with the spinbox buttons (which is cumbersome anyway)

to use this value again. If the spinboxes will be exchanged with dropdowneditboxes one can enter values and/or choose a previous entered value.

Did i overlooked such a widget?


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 2057
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2024-02-26, 19:54

Widgets that do this are called Comboboxes. Widelands doesn't have such a widget built-in currently as we have no use case for it in the default UI.

What you could do is to put an editbox and a dropdown of type "pictorial_menu" next to each other, and add a callback to the dropdown so that selecting an entry replaces the editbox's text with the selected entry.
We do support adding entries to string dropdowns dynamically.


Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2551
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2024-02-27, 15:39

Ah, that's a good idea face-smile.png

I have trouble to get an image on the button of the dropdown if it is of type "pictorial_menu", the button remains always empty. The doc says:

  • "pictorial_menu": The shown icon remains always unchanged.

Where has this icon to be set? Or: To which icon "shown icon" refers? Applying an icon to the dropdown entries works, but the button is still blank. Trying to set an icon for in the main dropdown definition also doesn't work.

Codesnipped for testing, see attachment for the whole test addon)

               {
                  widget = "dropdown",
                  name   = "distance_x_dropdown",
                  label  = "",
                  icon = "images/ui_basic/scrollbar_down.png",      --doesn't work
                  button_dimension = 24,
                  button_style = "primary",
                  type   = "pictorial_menu",
                  datatype = "string",
                  entries = {
                     {
                        label = "1. entry",
                        value = 1,
                        select = true,
                        icon = "images/ui_basic/scrollbar_down.png"  -- doesn't work for the button
                     },
                     {
                        label = "2. entry",
                        value = 2,
                        select = false,
                        -- icon = "images/ui_basic/scrollbar_down.png"
                     },
                     {
                        label = "3. entry",
                        value = 3,
                        select = false,
                        -- icon = "images/ui_basic/scrollbar_down.png"
                     },
                  },
               },

Attachment:
test_pictorial_dropd.zip (1.4 KB)

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 2057
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2024-02-27, 17:08

Oops face-smile.png That's an oversight in the Lua UI API code, will make a branch to fix this


Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2551
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2024-02-27, 17:13

Thanks, glad that i didn't overlooked something again face-grin.png


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 2057
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2024-02-27, 17:25

https://codeberg.org/wl/widelands/pulls/4742


Top Quote