add RadioButton Lua class

This commit is contained in:
MihailRis
2024-11-18 07:11:07 +03:00
parent 8e1d6b9f03
commit 618a9f0411
3 changed files with 37 additions and 16 deletions
+23
View File
@@ -84,6 +84,29 @@ function Document.new(docname)
})
end
local _RadioGroup = {}
function _RadioGroup.set(self, key)
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(self, 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")
_MENU = _GUI_ROOT.menu
menu = _MENU