reorganize modules

This commit is contained in:
Eduardo Bart
2011-12-05 16:27:07 -02:00
parent ffeb34e0e7
commit cf0aab6d4d
90 changed files with 186 additions and 181 deletions

View File

@@ -0,0 +1,82 @@
MessageBox = {}
MessageBox.__index = MessageBox
-- messagebox flags
MessageBoxOk = 1
MessageBoxCancel = 2
function MessageBox.create(title, text, flags)
local box = {}
setmetatable(box, MessageBox)
-- create messagebox window
local window = UI.display('messagebox.otui', { locked = true })
window:setTitle(title)
local label = window:getChildById('messageBoxLabel')
label:setStyle('Label')
label:setText(text)
label:resizeToText()
-- set window size based on label size
window:setWidth(math.max(label:getWidth() + 48, 120))
window:setHeight(label:getHeight() + 64)
window:updateParentLayout()
-- setup messagebox first button
local buttonRight = window:getChildById('messageBoxRightButton')
if flags == MessageBoxOk then
buttonRight:setText("Ok")
box.onOk = EmptyFunction
buttonRight.onClick = function()
box.onOk()
box:destroy()
end
window.onEnter = buttonRight.onClick
window.onEscape = buttonRight.onClick
elseif flags == MessageBoxCancel then
buttonRight:setText("Cancel")
box.onCancel = EmptyFunction
buttonRight.onClick = function()
box.onCancel()
box:destroy()
end
window.onEnter = buttonRight.onClick
window.onEscape = buttonRight.onClick
end
box.window = window
return box
end
function MessageBox:destroy()
if self.onDestroy then
self.onDestroy()
self.onDestroy = nil
end
if self.window then
self.window:destroy()
self.window = nil
end
self.onOk = nil
self.onCancel = nil
end
-- shortcuts for creating message boxes
function displayMessageBox(title, text, flags)
return MessageBox.create(title, text, flags)
end
function displayErrorBox(title, text)
return MessageBox.create(title, text, MessageBoxOk)
end
function displayInfoBox(title, text)
return MessageBox.create(title, text, MessageBoxOk)
end
function displayCancelBox(title, text)
return MessageBox.create(title, text, MessageBoxCancel)
end

View File

@@ -0,0 +1,21 @@
Window
id: messageBoxWindow
anchors.centerIn: parent
height: 80
width: 120
Label
id: messageBoxLabel
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
margin-top: 27
margin-bottom : 27
Button
id: messageBoxRightButton
anchors.bottom: parent.bottom
anchors.right: parent.right
margin-right: 10
margin-bottom: 10
width: 64
visible: true