mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 04:21:50 +00:00
auto document variable in ui-document lua script
This commit is contained in:
parent
05589b721e
commit
ef0d4d69e4
5 changed files with 58 additions and 27 deletions
|
|
@ -1,6 +1,3 @@
|
|||
local Document = require("core:document")
|
||||
document = Document.new(DOC_NAME)
|
||||
|
||||
function on_open(invid)
|
||||
print("OPEN", invid)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
local Element = {}
|
||||
function Element.new(docname, name)
|
||||
return setmetatable({docname=docname, name=name}, {
|
||||
__index=function(self, k)
|
||||
return gui.getattr(self.docname, self.name, k)
|
||||
end,
|
||||
__newindex=function(self, k, v)
|
||||
gui.setattr(self.docname, self.name, k, v)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local Document = {}
|
||||
function Document.new(docname)
|
||||
return setmetatable({name=docname}, {
|
||||
__index=function(self, k)
|
||||
return Element.new(self.name, k)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
return Document
|
||||
|
|
@ -110,4 +110,27 @@ end
|
|||
color_mt = {}
|
||||
function color_mt.__tostring(self)
|
||||
return "rgba("..self[1]..", "..self[2]..", "..self[3]..", "..self[4]..")"
|
||||
end
|
||||
end
|
||||
|
||||
-- class designed for simple UI-nodes access via properties syntax
|
||||
local Element = {}
|
||||
function Element.new(docname, name)
|
||||
return setmetatable({docname=docname, name=name}, {
|
||||
__index=function(self, k)
|
||||
return gui.getattr(self.docname, self.name, k)
|
||||
end,
|
||||
__newindex=function(self, k, v)
|
||||
gui.setattr(self.docname, self.name, k, v)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
-- the engine automatically creates an instance for every ui document (layout)
|
||||
Document = {}
|
||||
function Document.new(docname)
|
||||
return setmetatable({name=docname}, {
|
||||
__index=function(self, k)
|
||||
return Element.new(self.name, k)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue