DialogProgramming - HydraFramework/Hydra GitHub Wiki

local ui = require "framework.ui"

local function myalert(_root, title, body)
	local view = ui.view{backgroundColor = 0, backgroundAlpha = 0.6}
	local center = ui.view{height = 100, margin="auto 20", backgroundColor = "lightgray"}
	view:addChild(center)
	local label = ui.label{text = title, height = 20, color = "white", backgroundColor = "blue"}
	center:addChild(label)
	local body = ui.label{text = body, margin = "25 5", color = "white", backgroundColor = "blue"}
	center:addChild(body)

	local running = coroutine.running()

	local v = nil

	local btn = ui.button{label = "OK", color = "black", backgroundColor = "white", margin = "auto auto 5 5", height = 15, width = 100, onclick = function()
		_root:removeChild(v)
		coroutine.resume(running, "OK_KEY")
	end}
	center:addChild(btn)

	local btn = ui.button{label = "Cancel", color = "black", backgroundColor = "white", margin = "auto 5 5 auto", height = 15, width = 100, onclick = function()
		_root:removeChild(v)
		coroutine.resume(running, "CANCEL_LEY")
	end}
	center:addChild(btn)

	v = _root:addChild(view)

	return coroutine.yield()
end

-- 以上代码放在公用的moudule中

print("alert begin")
local ret = myalert(_root, "test", "test body")
alert(string.format("alert ret=%s", ret))