change loadUI/UI.display lua API

This commit is contained in:
Eduardo Bart
2011-11-17 18:40:31 -02:00
parent 63cbe11f7e
commit 55136fe866
21 changed files with 88 additions and 45 deletions

View File

@@ -3,7 +3,7 @@ function table.dump(t, depth)
for k,v in pairs(t) do
str = string.rep(' ', depth * 2) .. k .. ': '
if type(v) ~= "table" then
print(str .. v)
print(str .. tostring(v))
else
print(str)
table.dump(v, depth+1)

View File

@@ -1,22 +1,38 @@
UI = { }
UI.root = getRootWidget()
function UI.loadAndDisplayLocked(otuiFile)
local widget = loadUI(otuiFile, UI.root)
UI.root:lockChild(widget)
-- public functions
function UI.display(arg1, options)
local widget
local parent
if options then parent = options.parent end
parent = parent or UI.root
-- display otui files
if type(arg1) == 'string' then
local otuiFilePath = resolveFileFullPath(arg1, 2)
widget = loadUI(otuiFilePath, parent)
-- display already loaded widgets
else
widget = arg1
if parent:hasChild(widget) then
widget:focus()
widget:show()
else
parent:addChild(widget)
widget:show()
end
end
-- apply display options
if widget and options then
for option,value in pairs(options) do
if option == 'locked' and value then
widget:lock()
elseif option == 'visible' then
widget:setVisible(value)
end
end
end
return widget
end
function UI.loadAndDisplay(otuiFile)
local widget = loadUI(otuiFile, UI.root)
return widget
end
function UI.display(widget)
UI.root:addChild(widget)
end
function UI.displayLocked(widget)
UI.root:addChild(widget)
UI.root:lockChild(widget)
end

View File

@@ -29,3 +29,27 @@ function dumpWidgets()
print(UI.root:getChildByIndex(i):getId())
end
end
function getCallingScriptSourcePath(depth)
depth = depth or 2
local info = debug.getinfo(1+depth, "Sn")
local path
if info.short_src then
path = info.short_src:match("(.*)/.*")
end
if not path then
path = '/'
elseif path:sub(0, 1) ~= '/' then
path = '/' .. path
end
return path
end
function resolveFileFullPath(filePath, depth)
depth = depth or 1
if filePath:sub(0, 1) ~= '/' then
return getCallingScriptSourcePath(depth+1) .. '/' .. filePath
else
return filePath
end
end