Add methods to HotkeyLabel

develop
Robob27 2023-02-08 13:00:13 -05:00
parent df5184d751
commit b950b56926
3 changed files with 26 additions and 0 deletions

@ -57,6 +57,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Lua ## Lua
- `overlay`: overlay widgets can now specify focus paths for the viewscreens they attach to so they only appear in specific contexts. see `overlay-dev-guide` for details. - `overlay`: overlay widgets can now specify focus paths for the viewscreens they attach to so they only appear in specific contexts. see `overlay-dev-guide` for details.
- ``widgets.CycleHotkeyLabel``: Added ``key_back`` optional parameter to cycle backwards. - ``widgets.CycleHotkeyLabel``: Added ``key_back`` optional parameter to cycle backwards.
- ``widgets.HotkeyLabel``: Added ``setLabel`` method to allow easily updating the label text without mangling the keyboard shortcut.
- ``widgets.HotkeyLabel``: Added ``setOnActivate`` method to allow easily updating the ``on_activate`` callback.
## Removed ## Removed

@ -4808,6 +4808,16 @@ It has the following attributes:
:on_activate: If specified, it is the callback that will be called whenever :on_activate: If specified, it is the callback that will be called whenever
the hotkey is pressed or the label is clicked. the hotkey is pressed or the label is clicked.
The HotkeyLabel widget implements the following methods:
* ``hotkeylabel:setLabel(label)``
Updates the label without altering the hotkey text.
* ``hotkeylabel:setOnActivate(on_activate)``
Updates the on_activate callback.
CycleHotkeyLabel class CycleHotkeyLabel class
---------------------- ----------------------

@ -1419,6 +1419,20 @@ HotkeyLabel.ATTRS{
} }
function HotkeyLabel:init() function HotkeyLabel:init()
self:initializeLabel()
end
function HotkeyLabel:setOnActivate(on_activate)
self.on_activate = on_activate
self:initializeLabel()
end
function HotkeyLabel:setLabel(label)
self.label = label
self:initializeLabel()
end
function HotkeyLabel:initializeLabel()
self:setText{{key=self.key, key_sep=self.key_sep, text=self.label, self:setText{{key=self.key, key_sep=self.key_sep, text=self.label,
on_activate=self.on_activate}} on_activate=self.on_activate}}
end end