add TextButton

develop
Myk Taylor 2023-07-16 20:24:39 -07:00
parent 2cd226d879
commit 2d2ecf6f0d
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
3 changed files with 57 additions and 2 deletions

@ -65,6 +65,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``dfhack.items.markForTrade``: mark items for trade - ``dfhack.items.markForTrade``: mark items for trade
- ``dfhack.items.isRequestedTradeGood``: discover whether an item is named in a trade agreement with an active caravan - ``dfhack.items.isRequestedTradeGood``: discover whether an item is named in a trade agreement with an active caravan
- ``dfhack.items.getValue``: gained optional ``caravan`` and ``caravan_buying`` parameters for prices that take trader races and agreements into account - ``dfhack.items.getValue``: gained optional ``caravan`` and ``caravan_buying`` parameters for prices that take trader races and agreements into account
- ``widgets.TextButton``: wraps a ``HotkeyLabel`` and decorates it to look more like a button
## Removed ## Removed

@ -5063,13 +5063,21 @@ The CycleHotkeyLabel widget implements the following methods:
selected option if no index is given. If an option was defined as just a selected option if no index is given. If an option was defined as just a
string, then this function will return ``nil`` for that option. string, then this function will return ``nil`` for that option.
ToggleHotkeyLabel ToggleHotkeyLabel class
----------------- -----------------------
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``). The ``On`` (with a value of ``true``) and ``Off`` (with a value of ``false``). The
``On`` option is rendered in green. ``On`` option is rendered in green.
TextButton class
----------------
This is a Panel subclass that wraps a HotkeyLabel with some decorators on the
sides to make it look more like a button, suitable for both graphics and ASCII
mdoes. All HotkeyLabel parameters passed to the constructor are passed through
to the wrapped HotkeyLabel.
List class List class
---------- ----------

@ -1489,6 +1489,52 @@ function HotkeyLabel:onInput(keys)
end end
end end
----------------
-- TextButton --
----------------
TextButton = defclass(TextButton, Panel)
local BUTTON_PEN = dfhack.pen.parse{fg=COLOR_YELLOW, bg=COLOR_RED}
function TextButton:init(info)
self.label = HotkeyLabel{
frame={t=0, l=1, r=1},
key=info.key,
key_sep=info.key_sep,
label=info.label,
on_activate=info.on_activate,
text_pen=info.text_pen,
text_dpen=info.text_dpen,
text_hpen=info.text_hpen,
disabled=info.disabled,
enabled=info.enabled,
auto_height=info.auto_height,
auto_width=info.auto_width,
on_click=info.on_click,
on_rclick=info.on_rclick,
scroll_keys=info.scroll_keys,
}
self:addviews{
Label{
frame={t=0, l=0, w=1},
text=string.char(221), -- half-width stripe on left
text_pen=BUTTON_PEN,
},
self.label,
Label{
frame={t=0, r=0, w=1},
text=string.char(222), -- half-width stripe on right
text_pen=BUTTON_PEN,
}
}
end
function TextButton:setLabel(label)
self.label:setLabel(label)
end
---------------------- ----------------------
-- CycleHotkeyLabel -- -- CycleHotkeyLabel --
---------------------- ----------------------