mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31:49 +00:00
feat: menu pages dispatching
This commit is contained in:
parent
43dc88c6b5
commit
1a246e2ae0
3 changed files with 23 additions and 2 deletions
|
|
@ -1,4 +1,6 @@
|
|||
local gui_util = {}
|
||||
local gui_util = {
|
||||
local_dispatchers = {}
|
||||
}
|
||||
|
||||
--- Parse `pagename?arg1=value1&arg2=value2` queries
|
||||
--- @param query page query string
|
||||
|
|
@ -25,6 +27,11 @@ end
|
|||
--- @return document_id
|
||||
function gui_util.load_page(query)
|
||||
local name, args = gui_util.parse_query(query)
|
||||
for i = #gui_util.local_dispatchers, 1, -1 do
|
||||
local newname, newargs = gui_util.local_dispatchers[i](name, args)
|
||||
name = newname or name
|
||||
args = newargs or args
|
||||
end
|
||||
local filename = file.find(string.format("layouts/pages/%s.xml", name))
|
||||
if filename then
|
||||
name = file.prefix(filename)..":pages/"..name
|
||||
|
|
@ -33,4 +40,15 @@ function gui_util.load_page(query)
|
|||
end
|
||||
end
|
||||
|
||||
function gui_util.add_page_dispatcher(dispatcher)
|
||||
if type(dispatcher) ~= "function" then
|
||||
error("function expected")
|
||||
end
|
||||
table.insert(gui_util.local_dispatchers, dispatcher)
|
||||
end
|
||||
|
||||
function gui_util.reset_local()
|
||||
gui_util.local_dispatchers = {}
|
||||
end
|
||||
|
||||
return gui_util
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue