-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordbar.lua
More file actions
77 lines (59 loc) · 1.54 KB
/
Wordbar.lua
File metadata and controls
77 lines (59 loc) · 1.54 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
-- Wordbar.lua
local globalData = require 'globalData'
local Ivory = require 'Ivory'
local Wordbar = {}
Wordbar.__index = Wordbar
function Wordbar.new()
local o = {}
-- assert(self==Wordbar)
setmetatable(o, Wordbar)
do
local dim = globalData.dim
o.rect = display.newRect(globalData.uiGroup, dim.wordbarX, dim.wordbarY, dim.wordbarWidth, dim.wordbarHeight)
o.rect:setFillColor(0.1,0.1,0.1)
o.rect.alpha = 0.1
end
o.center = display.newGroup()
globalData.uiGroup:insert(o.center)
return o
end
--[[
function Wordbar:destroy()
display.remove(self.rect)
display.remove(self.left)
display.remove(self.center)
display.remove(self.right)
end
]]
function Wordbar:setCenter(s)
-- self:set('center', s)
local dim = globalData.dim
if not self.center then -- timed out, object deleted
return
end
if not self.center.numChildren then -- timed out, object deleted
return
end
while self.center.numChildren > 0 do
self.center[1]:removeSelf()
end
-- too slow!
-- local found = s and Util.isWordInDictionary(s) or false
if s then
local x = dim.halfQ
for i=1, string.len(s) do
-- Ivory.new creates a grp which it inserts into self.center
Ivory.new({
parent = self.center,
x = x,
y = dim.wordbarY,
text = string.sub(s, i, i),
scale = 0.5,
})
x = x + dim.halfQ
end
-- the first ivory is dim.halfQ over to the right
self.center.x = display.contentCenterX - (string.len(s) * dim.quarterQ) - dim.quarterQ
end
end
return Wordbar