Skip to content

Commit eef4fc5

Browse files
committed
devel/dflayout: provide on_render hook to demos
Keeps the secondary toolbar demo from needing to hook into the center toolbar (or some other "always on" widget) to notice changes in the secondary toolbar.
1 parent 7a63210 commit eef4fc5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

devel/dflayout.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local utils = require('utils')
99
---@field active? boolean whether the main window has enabled this demo (managed by main window)
1010
---@field views gui.View[] list of views to add to main ZScreen
1111
---@field update fun() called by main window to recompute demo frames
12+
---@field on_render? fun() called by main window every render; useful to notice changes in overall UI state
1213

1314
if visible_when_not_focused == nil then
1415
visible_when_not_focused = true
@@ -274,14 +275,12 @@ fort_toolbars_demo.update = function()
274275
end
275276

276277
local secondary
277-
local center_render = center_toolbar_demo.render
278-
function center_toolbar_demo:render(...)
278+
fort_toolbars_demo.on_render = function()
279279
local new_secondary = active_secondary()
280280
if new_secondary ~= secondary then
281281
secondary = new_secondary
282282
update_fort_toolbars(secondary)
283283
end
284-
return center_render(self, ...)
285284
end
286285

287286
--- Demo Control Window and Screen ---
@@ -375,6 +374,11 @@ function DemoScreen:render(...)
375374
if_percentage = new_if_percentage
376375
self:updateLayout()
377376
end
377+
for _, demo in ipairs(self.demos) do
378+
if demo.on_render and demo.available() and demo.active then
379+
demo.on_render()
380+
end
381+
end
378382
end
379383
return DemoScreen.super.render(self, ...)
380384
end

0 commit comments

Comments
 (0)