let CycleHotkeyLabels take numeric initial_options

even if all of the option values are non-numeric
develop
myk002 2022-05-18 14:04:56 -07:00 committed by Myk
parent 47b87a5ac1
commit 53609db1f9
3 changed files with 24 additions and 0 deletions

@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## New Tweaks ## New Tweaks
## Fixes ## Fixes
- ``widgets.CycleHotkeyLabel``: allow initial option values to be specified as an index instead of an option value
## Misc Improvements ## Misc Improvements
- `dfhack-examples-guide`: refine food preparation orders and fix conditions for making jugs and pots in the ``basic`` manager orders - `dfhack-examples-guide`: refine food preparation orders and fix conditions for making jugs and pots in the ``basic`` manager orders

@ -637,6 +637,11 @@ function CycleHotkeyLabel:init()
break break
end end
end end
if not self.option_idx then
if self.options[self.initial_option] then
self.option_idx = self.initial_option
end
end
if not self.option_idx then if not self.option_idx then
error(('cannot find option with value or index: "%s"') error(('cannot find option with value or index: "%s"')
:format(self.initial_option)) :format(self.initial_option))

@ -0,0 +1,18 @@
local widgets = require('gui.widgets')
function test.togglehotkeylabel()
local toggle = widgets.ToggleHotkeyLabel{}
expect.true_(toggle:getOptionValue())
toggle:cycle()
expect.false_(toggle:getOptionValue())
toggle:cycle()
expect.true_(toggle:getOptionValue())
end
function test.togglehotkeylabel_default_value()
local toggle = widgets.ToggleHotkeyLabel{initial_option=2}
expect.false_(toggle:getOptionValue())
toggle = widgets.ToggleHotkeyLabel{initial_option=false}
expect.false_(toggle:getOptionValue())
end