diff --git a/docs/changelog.txt b/docs/changelog.txt index 7010bdd31..4a3428031 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -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 diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index f9aafe4e0..9f2386660 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -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`` diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index ab018a50a..b86e31710 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -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