Merge pull request #3649 from myk002/myk_bannerpanel

[widgets] factor banner out into reusable panel class
develop
Myk 2023-08-07 12:54:32 -07:00 committed by GitHub
commit 139a3a5ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 22 deletions

@ -70,6 +70,7 @@ Template for new versions:
## 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()``
- ``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

@ -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`` 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
----------------
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.
This is a BannerPanel 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 modes. All HotkeyLabel parameters passed to the constructor are passed
through to the wrapped HotkeyLabel.
List class
----------

@ -1489,13 +1489,27 @@ function HotkeyLabel:onInput(keys)
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 = defclass(TextButton, Panel)
local BUTTON_PEN = dfhack.pen.parse{fg=COLOR_YELLOW, bg=COLOR_RED}
TextButton = defclass(TextButton, BannerPanel)
function TextButton:init(info)
self.label = HotkeyLabel{
@ -1516,19 +1530,7 @@ function TextButton:init(info)
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,
}
}
self:addviews{self.label}
end
function TextButton:setLabel(label)

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