Create manipulation functions for UI elements, sandboxing functions.
parent
d80fdccde4
commit
000e07101d
|
@ -22,49 +22,68 @@ elem_mt = {
|
|||
rawset(rawget(elem, "traits"), key, val)
|
||||
end,
|
||||
|
||||
get = function(tbl, key)
|
||||
if type(key) == number then return rawget(tbl, "children")[key] end
|
||||
__call = function(tbl, fn)
|
||||
setfenv(fn, env)
|
||||
return fn(tbl)
|
||||
end,
|
||||
|
||||
find = function(tbl, key)
|
||||
for _,v in pairs(rawget(tbl, "children")) do
|
||||
if v == key then return v end
|
||||
if v.key == key then return v end
|
||||
local c = v:find(key)
|
||||
if c ~= nil then return c end
|
||||
end
|
||||
end,
|
||||
|
||||
append = function(tbl, elem)
|
||||
if type(elem) == "function" then elem = zepha.build_ui(elem) end
|
||||
if type(elem) == "function" then elem = zepha.build_gui(elem) end
|
||||
rawset(elem, "parent", tbl)
|
||||
table.insert(rawget(tbl, "children"), elem)
|
||||
end,
|
||||
|
||||
prepend = function(tbl, elem)
|
||||
if type(elem) == "function" then elem = zepha.build_ui(elem) end
|
||||
table.insert(rawget(tbl, "children"), 0, elem)
|
||||
if type(elem) == "function" then elem = zepha.build_gui(elem) end
|
||||
rawset(elem, "parent", tbl)
|
||||
table.insert(rawget(tbl, "children"), 1, elem)
|
||||
end,
|
||||
|
||||
remove = function(tbl)
|
||||
if tbl.parent == nil then return end
|
||||
local ind = 0
|
||||
for k,v in pairs(tbl.parent.children) do
|
||||
if v == tbl then ind = k end
|
||||
end
|
||||
if ind == 0 then return end
|
||||
table.remove(tbl.parent.children, ind)
|
||||
return tbl
|
||||
end
|
||||
}
|
||||
|
||||
-- create_element
|
||||
-- Build a GUI Element with the provided constructor data, apply the metatable.
|
||||
local function create_element(elem_type, data)
|
||||
local element = {}
|
||||
local element = {
|
||||
type = elem_type,
|
||||
key = "",
|
||||
|
||||
element.type = elem_type
|
||||
element.children = {}
|
||||
element.callbacks = {}
|
||||
element.traits = {}
|
||||
element.key = ""
|
||||
parent = nil,
|
||||
children = {},
|
||||
|
||||
callbacks = {},
|
||||
traits = {}
|
||||
}
|
||||
|
||||
setmetatable(element, elem_mt)
|
||||
|
||||
for k, v in pairs(data) do
|
||||
if type(k) == "number" then
|
||||
rawset(v, "parent", element)
|
||||
table.insert(element.children, v)
|
||||
elseif k == "key" then
|
||||
element.key = v
|
||||
elseif k == "callbacks" then
|
||||
element.callbacks = v
|
||||
else
|
||||
element.traits[k] = v
|
||||
element[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
setmetatable(element, elem_mt)
|
||||
return element
|
||||
end
|
||||
|
||||
|
|
|
@ -1,12 +1,38 @@
|
|||
local menu = zepha.build_gui(function()
|
||||
return Gui.Body {
|
||||
background = "#214a21",
|
||||
return Gui.Body {
|
||||
background = "#214a21",
|
||||
|
||||
Gui.Text {
|
||||
position = { 4, 4 },
|
||||
content = "Minimal Subgame"
|
||||
}
|
||||
}
|
||||
Gui.Text {
|
||||
position = { 4, 4 },
|
||||
content = "Minimal Subgame"
|
||||
},
|
||||
|
||||
Gui.Rect {
|
||||
position = { 64, 64 },
|
||||
size = { 128 * (16/9), 128 },
|
||||
|
||||
background = "zeus_background"
|
||||
},
|
||||
|
||||
Gui.Rect {
|
||||
position = { 64 + 128, 64 + 64 },
|
||||
size = { 128 * (16/9), 128 },
|
||||
|
||||
background = "zeus_background",
|
||||
|
||||
Gui.Text {
|
||||
content = "What's the fuck is going on?"
|
||||
}
|
||||
}
|
||||
}
|
||||
end)
|
||||
|
||||
menu(function(e)
|
||||
e:append(Gui.Text {
|
||||
position = { 300, 16 },
|
||||
color = "#0fc",
|
||||
content = "Magic phones"
|
||||
})
|
||||
end)
|
||||
|
||||
zepha.set_gui(menu)
|
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
Loading…
Reference in New Issue