add label_below attribute

develop
Myk Taylor 2023-02-27 04:13:05 -08:00
parent 0f2c88265e
commit a5d22705e8
No known key found for this signature in database
3 changed files with 12 additions and 3 deletions

@ -50,6 +50,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``dfhack.job.attachJobItem()``: allows you to attach specific items to a job - ``dfhack.job.attachJobItem()``: allows you to attach specific items to a job
- ``dfhack.screen.paintTile()``: you can now explicitly clear the interface cursor from a map tile by passing ``0`` as the tile value - ``dfhack.screen.paintTile()``: you can now explicitly clear the interface cursor from a map tile by passing ``0`` as the tile value
- ``widgets.Label``: token ``tile`` properties can now be functions that return a value - ``widgets.Label``: token ``tile`` properties can now be functions that return a value
- ``widgets.CycleHotkeyLabel``: add ``label_below`` attribute for compact 2-line output
-@ ``widgets.FilteredList``: search key matching is now case insensitive by default -@ ``widgets.FilteredList``: search key matching is now case insensitive by default
-@ ``gui.INTERIOR_FRAME``: a panel frame style for use in highlighting off interior areas of a UI -@ ``gui.INTERIOR_FRAME``: a panel frame style for use in highlighting off interior areas of a UI

@ -4896,6 +4896,8 @@ 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).
:label_below: If ``true``, then the option value will apear below the label
instead of to the right of it. Defaults to ``false``.
:options: A list of strings or tables of :options: A list of strings or tables of
``{label=string, value=string[, pen=pen]}``. String options use the same ``{label=string, value=string[, pen=pen]}``. String options use the same
string for the label and value and the default pen. The optional ``pen`` string for the label and value and the default pen. The optional ``pen``

@ -1490,6 +1490,7 @@ CycleHotkeyLabel.ATTRS{
key_back=DEFAULT_NIL, key_back=DEFAULT_NIL,
label=DEFAULT_NIL, label=DEFAULT_NIL,
label_width=DEFAULT_NIL, label_width=DEFAULT_NIL,
label_below=false,
options=DEFAULT_NIL, options=DEFAULT_NIL,
initial_option=1, initial_option=1,
on_change=DEFAULT_NIL, on_change=DEFAULT_NIL,
@ -1498,12 +1499,17 @@ CycleHotkeyLabel.ATTRS{
function CycleHotkeyLabel:init() function CycleHotkeyLabel:init()
self:setOption(self.initial_option) self:setOption(self.initial_option)
local val_gap = 1
if self.label_below then
val_gap = 0 + (self.key_back and 1 or 0) + (self.key and 3 or 0)
end
self:setText{ self:setText{
self.key_back ~= nil and {key=self.key_back, key_sep='', width=0, on_activate=self:callback('cycle', true)} or {}, self.key_back ~= nil and {key=self.key_back, key_sep='', width=0, on_activate=self:callback('cycle', true)} or {},
{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')},
' ', self.label_below and NEWLINE or '',
{text=self:callback('getOptionLabel'), {gap=val_gap, text=self:callback('getOptionLabel'),
pen=self:callback('getOptionPen')}, pen=self:callback('getOptionPen')},
} }
end end
@ -1580,7 +1586,7 @@ end
function CycleHotkeyLabel:onInput(keys) function CycleHotkeyLabel:onInput(keys)
if CycleHotkeyLabel.super.onInput(self, keys) then if CycleHotkeyLabel.super.onInput(self, keys) then
return true return true
elseif keys._MOUSE_L_DOWN and self:getMousePos() then elseif keys._MOUSE_L_DOWN and self:getMousePos() and not is_disabled(self) then
self:cycle() self:cycle()
return true return true
end end