move Document and RadioGroup implementation to core:gui_util
This commit is contained in:
parent
b0a8e8e001
commit
72d2d9c879
@ -51,4 +51,57 @@ function gui_util.reset_local()
|
|||||||
gui_util.local_dispatchers = {}
|
gui_util.local_dispatchers = {}
|
||||||
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)
|
||||||
|
local Document = {}
|
||||||
|
function Document.new(docname)
|
||||||
|
return setmetatable({name=docname}, {
|
||||||
|
__index=function(self, k)
|
||||||
|
local elem = Element.new(self.name, k)
|
||||||
|
rawset(self, k, elem)
|
||||||
|
return elem
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local RadioGroup = {}
|
||||||
|
function RadioGroup:set(key)
|
||||||
|
if type(self) ~= 'table' then
|
||||||
|
error("called as non-OOP via '.', use radiogroup:set")
|
||||||
|
end
|
||||||
|
if self.current then
|
||||||
|
self.elements[self.current].enabled = true
|
||||||
|
end
|
||||||
|
self.elements[key].enabled = false
|
||||||
|
self.current = key
|
||||||
|
if self.callback then
|
||||||
|
self.callback(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function RadioGroup:__call(elements, onset, default)
|
||||||
|
local group = setmetatable({
|
||||||
|
elements=elements,
|
||||||
|
callback=onset,
|
||||||
|
current=nil
|
||||||
|
}, {__index=RadioGroup})
|
||||||
|
group:set(default)
|
||||||
|
return group
|
||||||
|
end
|
||||||
|
setmetatable(RadioGroup, RadioGroup)
|
||||||
|
|
||||||
|
gui_util.Document = Document
|
||||||
|
gui_util.RadioGroup = RadioGroup
|
||||||
|
|
||||||
return gui_util
|
return gui_util
|
||||||
|
|||||||
@ -146,64 +146,16 @@ function events.emit(event, ...)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
-- class designed for simple UI-nodes access via properties syntax
|
gui_util = require "core:gui_util"
|
||||||
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 = gui_util.Document
|
||||||
Document = {}
|
RadioGroup = gui_util.RadioGroup
|
||||||
function Document.new(docname)
|
__vc_page_loader = gui_util.load_page
|
||||||
return setmetatable({name=docname}, {
|
|
||||||
__index=function(self, k)
|
|
||||||
local elem = Element.new(self.name, k)
|
|
||||||
rawset(self, k, elem)
|
|
||||||
return elem
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local _RadioGroup = {}
|
|
||||||
function _RadioGroup:set(key)
|
|
||||||
if type(self) ~= 'table' then
|
|
||||||
error("called as non-OOP via '.', use radiogroup:set")
|
|
||||||
end
|
|
||||||
if self.current then
|
|
||||||
self.elements[self.current].enabled = true
|
|
||||||
end
|
|
||||||
self.elements[key].enabled = false
|
|
||||||
self.current = key
|
|
||||||
if self.callback then
|
|
||||||
self.callback(key)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function _RadioGroup:__call(elements, onset, default)
|
|
||||||
local group = setmetatable({
|
|
||||||
elements=elements,
|
|
||||||
callback=onset,
|
|
||||||
current=nil
|
|
||||||
}, {__index=_RadioGroup})
|
|
||||||
group:set(default)
|
|
||||||
return group
|
|
||||||
end
|
|
||||||
setmetatable(_RadioGroup, _RadioGroup)
|
|
||||||
RadioGroup = _RadioGroup
|
|
||||||
|
|
||||||
_GUI_ROOT = Document.new("core:root")
|
_GUI_ROOT = Document.new("core:root")
|
||||||
_MENU = _GUI_ROOT.menu
|
_MENU = _GUI_ROOT.menu
|
||||||
menu = _MENU
|
menu = _MENU
|
||||||
|
|
||||||
gui_util = require "core:gui_util"
|
|
||||||
__vc_page_loader = gui_util.load_page
|
|
||||||
|
|
||||||
--- Console library extension ---
|
--- Console library extension ---
|
||||||
console.cheats = {}
|
console.cheats = {}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user