Merge pull request #2562 from myk002/myk_greenify

allow color options for CycleHotkeyLabel
develop
Myk 2023-01-06 19:10:39 -08:00 committed by GitHub
commit fe9d1e186e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 13 deletions

@ -54,6 +54,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``gui.View``: ``visible`` and ``active`` can now be functions that return a boolean - ``gui.View``: ``visible`` and ``active`` can now be functions that return a boolean
- ``widgets.Panel``: new attributes to control window dragging and resizing with mouse or keyboard - ``widgets.Panel``: new attributes to control window dragging and resizing with mouse or keyboard
- ``widgets.Window``: Panel subclass with attributes preset for top-level windows - ``widgets.Window``: Panel subclass with attributes preset for top-level windows
- ``widgets.CycleHotkeyLabel``: now supports rendering option labels in the color of your choice
- ``widgets.ToggleHotkeyLabel``: now renders the ``On`` option in green text
- `overlay`: ``OverlayWidget`` now inherits from ``Panel`` instead of ``Widget`` to get all the frame and mouse integration goodies - `overlay`: ``OverlayWidget`` now inherits from ``Panel`` instead of ``Widget`` to get all the frame and mouse integration goodies
- ``dfhack.gui.getDFViewscreen()``: returns the topmost underlying DF viewscreen - ``dfhack.gui.getDFViewscreen()``: returns the topmost underlying DF viewscreen
- ``gui.ZScreen``: Screen subclass that implements window raising, multi-viewscreen input handling, and viewscreen event pass-through so the underlying map can be interacted with and dragged around while DFHack screens are visible - ``gui.ZScreen``: Screen subclass that implements window raising, multi-viewscreen input handling, and viewscreen event pass-through so the underlying map can be interacted with and dragged around while DFHack screens are visible

@ -4717,8 +4717,10 @@ It has the following attributes:
hotkey. hotkey.
:label_width: The number of spaces to allocate to the ``label`` (for use in :label_width: The number of spaces to allocate to the ``label`` (for use in
aligning a column of ``CycleHotkeyLabel`` labels). aligning a column of ``CycleHotkeyLabel`` labels).
:options: A list of strings or tables of ``{label=string, value=string}``. :options: A list of strings or tables of
String options use the same string for the label and value. ``{label=string, value=string[, pen=pen]}``. String options use the same
string for the label and value and the default pen. The optional ``pen``
element could be a color like ``COLOR_RED``.
:initial_option: The value or numeric index of the initial option. :initial_option: The value or numeric index of the initial option.
:on_change: The callback to call when the selected option changes. It is called :on_change: The callback to call when the selected option changes. It is called
as ``on_change(new_option_value, old_option_value)``. as ``on_change(new_option_value, old_option_value)``.
@ -4746,7 +4748,8 @@ ToggleHotkeyLabel
----------------- -----------------
This is a specialized subclass of CycleHotkeyLabel that has two options: This is a specialized subclass of CycleHotkeyLabel that has two options:
``On`` (with a value of ``true``) and ``Off`` (with a value of ``false``). ``On`` (with a value of ``true``) and ``Off`` (with a value of ``false``). The
``On`` option is rendered in green.
List class List class
---------- ----------

@ -1436,7 +1436,8 @@ function CycleHotkeyLabel:init()
{key=self.key, key_sep=': ', text=self.label, width=self.label_width, {key=self.key, key_sep=': ', text=self.label, width=self.label_width,
on_activate=self:callback('cycle')}, on_activate=self:callback('cycle')},
' ', ' ',
{text=self:callback('getOptionLabel')}, {text=self:callback('getOptionLabel'),
pen=self:callback('getOptionPen')},
} }
end end
@ -1453,22 +1454,27 @@ function CycleHotkeyLabel:cycle()
end end
end end
function CycleHotkeyLabel:getOptionLabel(option_idx) local function cyclehotkeylabel_getOptionElem(self, option_idx, key)
option_idx = option_idx or self.option_idx option_idx = option_idx or self.option_idx
local option = self.options[option_idx] local option = self.options[option_idx]
if type(option) == 'table' then if type(option) == 'table' then
return option.label return option[key]
end end
return option return option
end end
function CycleHotkeyLabel:getOptionLabel(option_idx)
return cyclehotkeylabel_getOptionElem(self, option_idx, 'label')
end
function CycleHotkeyLabel:getOptionValue(option_idx) function CycleHotkeyLabel:getOptionValue(option_idx)
option_idx = option_idx or self.option_idx return cyclehotkeylabel_getOptionElem(self, option_idx, 'value')
local option = self.options[option_idx]
if type(option) == 'table' then
return option.value
end end
return option
function CycleHotkeyLabel:getOptionPen(option_idx)
local pen = cyclehotkeylabel_getOptionElem(self, option_idx, 'pen')
if type(pen) == 'string' then return nil end
return pen
end end
function CycleHotkeyLabel:onInput(keys) function CycleHotkeyLabel:onInput(keys)
@ -1486,7 +1492,7 @@ end
ToggleHotkeyLabel = defclass(ToggleHotkeyLabel, CycleHotkeyLabel) ToggleHotkeyLabel = defclass(ToggleHotkeyLabel, CycleHotkeyLabel)
ToggleHotkeyLabel.ATTRS{ ToggleHotkeyLabel.ATTRS{
options={{label='On', value=true}, options={{label='On', value=true, pen=COLOR_GREEN},
{label='Off', value=false}}, {label='Off', value=false}},
} }