Skip to content

Commit

Permalink
Merge pull request #3649 from myk002/myk_bannerpanel
Browse files Browse the repository at this point in the history
[widgets] factor banner out into reusable panel class
  • Loading branch information
myk002 authored Aug 7, 2023
2 parents b1c1c1b + 8c16693 commit 139a3a5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
34 changes: 18 additions & 16 deletions library/lua/gui/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions plugins/lua/zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 139a3a5

Please sign in to comment.