Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --примерные данные кнопки
- --код запускать на corona sdk старге 2 поколения
- someJSON = [[{
- "type" : "Button",
- "parent" : "PerentControlName",
- "text" : "Кнопка 1",
- "name" : "Button1",
- "position" : {
- "x" : 100,
- "y" : 100
- },
- "on_click" : "onClickMethodName",
- "children" : ["path/to/first/child/element.json","path/to/last/child/element.json"]
- }]]
- function CreateUIElement( data )
- local json = require( "json" ) -- подгружаем модуль жижсона
- local widget = require( "widget" ) -- либа для кнопок от coronaSDK (годный контент огромные возможности кастомизации )
- local decoded, pos, msg = json.decode( data ) -- создаем таблицу из жижсона
- if not decoded then -- отрабочик ошибок
- print( "Decode failed at " .. tostring(pos) .. ": " .. tostring(msg) )
- else
- newObj = {}
- newObj.type = decoded.type
- newObj.parent = decoded.parent
- newObj.children = {}
- for i,v in ipairs(decoded.children) do
- newObj.children[i] = v
- end
- local newObj = widget.newButton(
- {
- label = decoded.name,
- onEvent = decoded.on_click,
- emboss = false,
- shape = "roundedRect",
- width = 200,
- height = 40,
- cornerRadius = 2,
- fillColor = { default={1,0,0,1}, over={1,0.1,0.2,1} }
- }
- )
- newObj.x = decoded.position.x
- newObj.y = decoded.position.y
- newObj:setLabel( decoded.text )
- end
- return newObj
- end
- myBut = CreateUIElement( someJSON )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement