add RadioButton Lua class
This commit is contained in:
parent
8e1d6b9f03
commit
618a9f0411
@ -1,9 +1,9 @@
|
||||
<container size='668,418' color='#0F1E2DB2' context='menu'>
|
||||
<panel pos='6' size='250' color='0' interval='1'>
|
||||
<button id='s_aud' onclick='set_page("s_aud", "settings_audio")'>@Audio</button>
|
||||
<button id='s_dsp' onclick='set_page("s_dsp", "settings_display")'>@Display</button>
|
||||
<button id='s_gfx' onclick='set_page("s_gfx", "settings_graphics")'>@Graphics</button>
|
||||
<button id='s_ctl' onclick='set_page("s_ctl", "settings_controls")'>@Controls</button>
|
||||
<button id='s_aud' onclick='sections:set("audio")'>@Audio</button>
|
||||
<button id='s_dsp' onclick='sections:set("display")'>@Display</button>
|
||||
<button id='s_gfx' onclick='sections:set("graphics")'>@Graphics</button>
|
||||
<button id='s_ctl' onclick='sections:set("controls")'>@Controls</button>
|
||||
</panel>
|
||||
<pagebox id='menu' pos='260,6' size='400'>
|
||||
</pagebox>
|
||||
@ -11,7 +11,7 @@
|
||||
<panel margin='6' gravity='bottom-left' size='250' color='0' interval='1'>
|
||||
<button onclick='menu.page="languages"' id='langs_btn'>-</button>
|
||||
<button onclick='core.open_folder("user:")'>@Open data folder</button>
|
||||
<button id='s_rst' onclick='set_page("s_rst", "settings_reset")'>@Reset settings</button>
|
||||
<button id='s_rst' onclick='sections:set("reset")'>@Reset settings</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
</container>
|
||||
|
||||
@ -3,15 +3,13 @@ function on_open()
|
||||
"%s: %s", gui.str("Language", "settings"),
|
||||
gui.get_locales_info()[core.get_setting("ui.language")].name
|
||||
)
|
||||
set_page("s_gfx", "settings_graphics")
|
||||
end
|
||||
|
||||
function set_page(btn, page)
|
||||
document.s_aud.enabled = true
|
||||
document.s_dsp.enabled = true
|
||||
document.s_gfx.enabled = true
|
||||
document.s_ctl.enabled = true
|
||||
document.s_rst.enabled = true
|
||||
document[btn].enabled = false
|
||||
document.menu.page = page
|
||||
sections = RadioGroup({
|
||||
audio=document.s_aud,
|
||||
display=document.s_dsp,
|
||||
graphics=document.s_gfx,
|
||||
controls=document.s_ctl,
|
||||
reset=document.s_rst
|
||||
}, function (page)
|
||||
document.menu.page = "settings_"..page
|
||||
end, "graphics")
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user