Skip to content

Commit c82195b

Browse files
authored
Merge pull request #4922 from wiktor-obrebski/feat/overlay-trigger-args
Pass CLI arguments to `overlay_trigger` function
2 parents 9b215a5 + 6c25e4e commit c82195b

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

docs/dev/overlay-dev-guide.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ beyond your everyday `widgets.Widget <widget>`:
7272
screen, but the returned screen can instantiate and configure any new views
7373
that it wants to. See the `hotkeys` DFHack logo widget for an example.
7474

75+
The ``overlay_trigger()`` function enables the activation of overlay widgets
76+
via the command line interface (CLI) or keybindings.
77+
For example, executing ``overlay trigger notes.map_notes add Kitchen``::
78+
79+
function MyOverlayWidget:overlay_trigger(arg1, arg2)
80+
if arg1 == 'add' then
81+
-- Add a new note to the map
82+
self:addSomething(arg2)
83+
elseif arg1 == 'delete' then
84+
self:deleteSomething(arg2)
85+
end
86+
end
87+
88+
This allows for dynamic updates to UI overlays directly from the CLI.
89+
7590
If the widget can take up a variable amount of space on the screen, and you want
7691
the widget to adjust its position according to the size of its contents, you can
7792
modify ``self.frame.w`` and ``self.frame.h`` at any time -- in ``init()`` or in

docs/plugins/overlay.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Examples
4949
``overlay trigger hotkeys.menu``
5050
Trigger the `hotkeys` menu widget so that it shows its popup menu. This is
5151
what is run when you hit :kbd:`Ctrl`:kbd:`Shift`:kbd:`C`.
52+
``overlay trigger notes.map_notes add Kitchen``
53+
Trigger the `notes` overlay widget so that it shows its new note popup
54+
with given title.
5255

5356
Widget position
5457
---------------

plugins/lua/overlay.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,11 @@ local function do_trigger(args, quiet)
383383
do_by_names_or_numbers(args[1], function(name, db_entry)
384384
local widget = db_entry.widget
385385
if widget.overlay_trigger then
386-
register_trigger_lock_screen(widget:overlay_trigger(), name)
386+
register_trigger_lock_screen(
387+
widget:overlay_trigger(table.unpack(args, 2)),
388+
name
389+
)
390+
387391
if not quiet then
388392
print(('triggered widget %s'):format(name))
389393
end

0 commit comments

Comments
 (0)