Files
paku/data/popup.lua
Raimon Zamora ddebcfa47a - [NEW] 'app' module
- [NEW] 'editor' module
- [NEW] 'msgbox' module
- [NEW] 'score' module
- [NEW] 'ui' module
- [NEW] 'util' module
2025-06-20 13:50:07 +02:00

52 lines
1.5 KiB
Lua

popup={
list = {},
old_update = nil,
current = nil,
create = function(label,x,y)
popup.list[label] = {x=x, y=y, width=50, options={}}
end,
addOption = function(parent, label, action)
popup.list[parent].options[#popup.list[parent].options+1] = { label=label, action=action }
local option_width = #label*4+4
if option_width > popup.list[parent].width then
popup.list[parent].width = option_width
end
end,
show = function(label)
popup.current = label
app.push(popup.update)
end,
update = function()
view.origin(0,0)
local mx, my = mouse.pos()
local p = popup.list[popup.current]
draw.outset(p.x, p.y, p.width, #p.options*7+2)
local y = p.y+2
for k,v in ipairs(p.options) do
local inside = util.inside(mx, my, {p.x, y-2, p.width, 7})
if inside then
draw.rectf(p.x+1, y-1, p.width-2, 7, 21)
if mouse.press(mouse.LEFT) then
app.pop()
v.action()
end
end
draw.text(v.label, p.x+2, y, 28)
y = y + 7
end
local inside = util.inside(mx, my, {p.x, p.y, p.width, #p.options*7+2})
if not inside and mouse.down(mouse.LEFT) then
mouse.discard()
app.pop()
end
if key.press(key.ESCAPE) then
app.pop()
end
end
}