Skip to content

Commit

Permalink
Merge pull request #5316 from myk002/myk_overlay_toggle_fns
Browse files Browse the repository at this point in the history
[overlay] add enable/disable hooks for widgets
  • Loading branch information
myk002 authored Feb 28, 2025
2 parents 137d16a + f4ff0ce commit beead5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Template for new versions:
- ``gui.dwarfmode``: adventure mode cursor now supported in ``getCursorPos``, ``setCursorPos``, and ``clearCursorPos`` funcitons
- ``dfhack.buildings.checkFreeTiles``: now replaces the extents parameter for a building pointer
- ``overlay.isOverlayEnabled``: new API for querying whether a given overlay is enabled
- ``overlay``: widgets can now declare ``overlay_onenable`` and ``overlay_ondisable`` functions to hook enable/disable

## Removed

Expand Down
5 changes: 5 additions & 0 deletions docs/dev/overlay-dev-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ beyond your everyday `widgets.Widget <widget>`:
end

This allows for dynamic updates to UI overlays directly from the CLI.
- If an ``overlay_onenable()`` function is defined, it is called when the
overlay is enabled (including when the persisted state is reloaded at DF
startup).
- If an ``overlay_ondisable()`` function is defined, it is called when the
overlay is disabled.

If the widget can take up a variable amount of space on the screen, and you want
the widget to adjust its position according to the size of its contents, you can
Expand Down
6 changes: 6 additions & 0 deletions plugins/lua/overlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ local function do_enable(args, quiet, skip_save)
vs_name = normalize_viewscreen_name(vs_name)
ensure_key(active_viewscreen_widgets, vs_name)[name] = db_entry
end
if db_entry.widget.overlay_onenable then
db_entry.widget.overlay_onenable()
end
if not quiet then
print(('enabled widget %s'):format(name))
end
Expand Down Expand Up @@ -202,6 +205,9 @@ local function do_disable(args, quiet)
active_viewscreen_widgets[vs_name] = nil
end
end
if db_entry.widget.overlay_ondisable then
db_entry.widget.overlay_ondisable()
end
if not quiet then
print(('disabled widget %s'):format(name))
end
Expand Down

0 comments on commit beead5d

Please sign in to comment.