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.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.CycleHotkeyLabel``: add ``label_below`` attribute for compact 2-line output
-@ ``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

@ -4896,6 +4896,8 @@ It has the following attributes:
hotkey.
:label_width: The number of spaces to allocate to the ``label`` (for use in
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
``{label=string, value=string[, pen=pen]}``. String options use the same
string for the label and value and the default pen. The optional ``pen``

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