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