-
Notifications
You must be signed in to change notification settings - Fork 1
/
toast.lua
56 lines (48 loc) · 1.42 KB
/
toast.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local toast = nil
local toastFont = native.systemFont
local toastFontSize = 14
local duration, objX, objY
function showToast(label, options)
local function removeToast()
if toast ~= nil then
if toast.label ~= nil then
toast.label:removeSelf()
toast.label = nil
end
toast:removeSelf()
toast = nil
end
end
removeToast()
if options ~= nil then
if options.duration == "short" then
duration = 1500
elseif options.duration == "normal" then
duration = 3000
elseif options.duration == "long" then
duration = 5000
end
if options.gravity == "center" then
objX = display.contentCenterX
objY = display.contentCenterY
elseif options.gravity == "top" then
objX = display.contentCenterX
objY = 36
elseif options.gravity == "bottom" then
objX = display.contentCenterX
objY = display.viewableContentHeight - 36
end
else
duration = 3000
objX = display.contentCenterX
objY = display.contentCenterY
end
toast = display.newRoundedRect(objX, objY, 32, 32, 32)
toast:setFillColor(0.5)
toast.alpha = 0.75
toast.label = display.newText(label, objX, objY, toastFont, toastFontSize)
toast.width = toast.label.contentWidth + 32
toast.height = toast.label.contentHeight + 10
timer.performWithDelay(duration, removeToast)
return true
end