-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu_stack.lua
More file actions
68 lines (54 loc) · 1.1 KB
/
menu_stack.lua
File metadata and controls
68 lines (54 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- Immersive is licensed under the terms of the GNU GPL v3: https://www.gnu.org/licenses/; © 2020 Ben Kerman
local stack = {}
local function exec_top(fn_name)
if #stack ~= 0 then
local top = stack[#stack]
top[fn_name](top)
end
end
local menu_stack = {}
function menu_stack.push(menu)
if not menu then return end
exec_top("hide")
table.insert(stack, menu)
exec_top("show")
end
function menu_stack.pop(count)
if not count then count = 1 end
for i = 1, count do
exec_top("cancel")
table.remove(stack)
end
exec_top("show")
end
function menu_stack.clear()
for _, menu in ipairs(stack) do
menu:cancel()
end
stack = {}
end
function menu_stack.save(count)
exec_top("hide")
local menus = {}
for i = 1, count do
table.insert(menus, table.remove(stack))
end
exec_top("show")
return menus
end
function menu_stack.restore(menus)
exec_top("hide")
for i = #menus, 1, -1 do
table.insert(stack, menus[i])
end
exec_top("show")
end
function menu_stack.drop(menus)
for _, menu in ipairs(menus) do
menu:cancel()
end
end
function menu_stack.top()
return stack[#stack]
end
return menu_stack