factor banner out into reusable panel class

develop
Myk Taylor 2023-08-07 12:40:48 -07:00
parent e57a5d665f
commit 8c166935d5
No known key found for this signature in database
4 changed files with 33 additions and 22 deletions

@ -69,6 +69,7 @@ Template for new versions:
## Lua ## Lua
- ``new()``: improved error handling so that certain errors that were previously uncatchable (creating objects with members with unknown vtables) are now catchable with ``pcall()`` - ``new()``: improved error handling so that certain errors that were previously uncatchable (creating objects with members with unknown vtables) are now catchable with ``pcall()``
- ``dfhack.items.getValue()``: remove ``caravan_buying`` param as per C++ API change - ``dfhack.items.getValue()``: remove ``caravan_buying`` param as per C++ API change
- ``widgets.BannerPanel``: panel with distinctive border for marking DFHack UI elements on otherwise vanilla screens
## Removed ## Removed

@ -5077,13 +5077,21 @@ 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.
BannerPanel class
-----------------
This is a Panel subclass that prints a distinctive banner along the far left
and right columns of the widget frame. Note that this is not a "proper" frame
since it doesn't have top or bottom borders. Subviews of this panel should
inset their frames one tile from the left and right edges.
TextButton class TextButton class
---------------- ----------------
This is a Panel subclass that wraps a HotkeyLabel with some decorators on the This is a BannerPanel subclass that wraps a HotkeyLabel with some decorators on
sides to make it look more like a button, suitable for both graphics and ASCII the sides to make it look more like a button, suitable for both graphics and
mdoes. All HotkeyLabel parameters passed to the constructor are passed through ASCII modes. All HotkeyLabel parameters passed to the constructor are passed
to the wrapped HotkeyLabel. through to the wrapped HotkeyLabel.
List class List class
---------- ----------

@ -1489,13 +1489,27 @@ function HotkeyLabel:onInput(keys)
end end
end end
-----------------
-- BannerPanel --
-----------------
BannerPanel = defclass(BannerPanel, Panel)
local BANNER_PEN = dfhack.pen.parse{fg=COLOR_YELLOW, bg=COLOR_RED}
function BannerPanel:onRenderBody(dc)
dc:pen(BANNER_PEN)
for y=0,self.frame_rect.height-1 do
dc:seek(0, y):char(string.char(221)) -- half-width stripe on left
dc:seek(self.frame_rect.width-1):char(string.char(222)) -- half-width stripe on right
end
end
---------------- ----------------
-- TextButton -- -- TextButton --
---------------- ----------------
TextButton = defclass(TextButton, Panel) TextButton = defclass(TextButton, BannerPanel)
local BUTTON_PEN = dfhack.pen.parse{fg=COLOR_YELLOW, bg=COLOR_RED}
function TextButton:init(info) function TextButton:init(info)
self.label = HotkeyLabel{ self.label = HotkeyLabel{
@ -1516,19 +1530,7 @@ function TextButton:init(info)
scroll_keys=info.scroll_keys, scroll_keys=info.scroll_keys,
} }
self:addviews{ self:addviews{self.label}
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 end
function TextButton:setLabel(label) function TextButton:setLabel(label)

@ -694,13 +694,13 @@ PastureOverlay.ATTRS{
function PastureOverlay:init() function PastureOverlay:init()
self:addviews{ self:addviews{
widgets.TextButton{ widgets.TextButton{
frame={t=0, l=0}, frame={t=0, l=0, r=0, h=1},
label='DFHack manage pasture', label='DFHack manage pasture',
key='CUSTOM_CTRL_T', key='CUSTOM_CTRL_T',
on_activate=function() view = view and view:raise() or PastureScreen{}:show() end, on_activate=function() view = view and view:raise() or PastureScreen{}:show() end,
}, },
widgets.TextButton{ widgets.TextButton{
frame={t=2, l=0}, frame={t=2, l=0, r=0, h=1},
label='DFHack autobutcher', label='DFHack autobutcher',
key='CUSTOM_CTRL_B', key='CUSTOM_CTRL_B',
on_activate=function() dfhack.run_script('gui/autobutcher') end, on_activate=function() dfhack.run_script('gui/autobutcher') end,