[posila][0.17.66] Listbox "selected_index" not updated programatically
Posted: Thu Aug 29, 2019 12:17 pm
The value "selected_index" of a listbox never updates when calling methods that modifies the item list, even "clear_items".
Steps to reproduce:
- Display a list with items
- Select the last item
- Print the selected item index
- Remove the last item
I expected the index to change to the last item if you removed the last item, either by becoming nil, 0 or by selecting the new last item, but index does not change at all. This can be problematic as the index is now pointing to a non-existant item in the list.
- Clear the list
The selected index is still the same as before. You have now a non-zero index in an empty list.
- Fill the list again
The selected index still didn't changed, but now the item does not appear selected in the list.
This also happen when you insert an item before the selected item : the highlighted item is not the one the selected index is pointing to.
Steps to reproduce:
- Display a list with items
Code: Select all
/c game.player.gui.center.add{type="list-box", name="list", items={"a", "b", "c"}}
- Print the selected item index
Code: Select all
/c game.print(game.player.gui.center["list"].selected_index)
Code: Select all
/c game.player.gui.center["list"].remove_item(3)
- Clear the list
Code: Select all
/c game.player.gui.center["list"].clear_items()
- Fill the list again
Code: Select all
/c game.player.gui.center["list"].add_item("d"); game.player.gui.center["list"].add_item("e"); game.player.gui.center["list"].add_item("f")
This also happen when you insert an item before the selected item : the highlighted item is not the one the selected index is pointing to.