Merge remote-tracking branch 'suokko/lua_List_setChoices_internal_table_1171' into develop

develop
lethosor 2018-07-03 00:27:22 -04:00
commit c449041c11
2 changed files with 9 additions and 6 deletions

@ -146,6 +146,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Lua ## Lua
- Added ``profiler`` module to measure lua performance - Added ``profiler`` module to measure lua performance
- Enabled shift+cursor movement in WorkshopOverlay-derived screens - Enabled shift+cursor movement in WorkshopOverlay-derived screens
- ``gui.widgets``: ``List:setChoices`` clones ``choices`` for internal table changes
## Structures ## Structures
- ``unit_flags1``: renamed ``dead`` to ``inactive`` to better reflect its use - ``unit_flags1``: renamed ``dead`` to ``inactive`` to better reflect its use

@ -456,15 +456,17 @@ function List:init(info)
end end
function List:setChoices(choices, selected) function List:setChoices(choices, selected)
self.choices = choices or {} self.choices = {}
for i,v in ipairs(self.choices) do for i,v in ipairs(choices or {}) do
local l = utils.clone(v);
if type(v) ~= 'table' then if type(v) ~= 'table' then
v = { text = v } l = { text = v }
self.choices[i] = v else
l.text = v.text or v.caption or v[1]
end end
v.text = v.text or v.caption or v[1] parse_label_text(l)
parse_label_text(v) self.choices[i] = l
end end
self:setSelected(selected) self:setSelected(selected)