-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.lua
240 lines (174 loc) · 7.64 KB
/
grid.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
local widget = require( "widget" )
local _W = display.contentWidth
local _H = display.contentHeight
local mF = math.floor
local L = {}
--L.tableView = nil
L.originalData = {}
L.modifiedData = {}
-- Variables changed by the code
local rowStartingYPosition = display.contentHeight/16
local rowHeight = display.contentHeight * .05
local fontSize = 20
local headerFontSize = 50
local fontName = native.systemFont
L.createTableData = function(entry, options)
local params = {}
for i, columns in ipairs(options.columnDataName) do
print("Column Data:", entry[options.columnDataName[i]])
params[i] = entry[options.columnDataName[i]]
end
return params
end
L.createCircle = function(width)
local closeCircleGrp = display.newGroup()
local closeCircle = display.newCircle( 0, 0, width)
closeCircle:setFillColor( 0, 0, 0)
local closeCircleLine1 = display.newLine(closeCircle.x - closeCircle.contentWidth/4, closeCircle.y - closeCircle.width/4, closeCircle.x + closeCircle.contentWidth/4, closeCircle.y + closeCircle.width/4)
closeCircleLine1.strokeWidth = 3
closeCircleLine1:setStrokeColor(1)
local closeCircleLine2 = display.newLine(closeCircle.x - closeCircle.contentWidth/4, closeCircle.y + closeCircle.width/4, closeCircle.x + closeCircle.contentWidth/4, closeCircle.y - closeCircle.width/4)
closeCircleLine2.strokeWidth = 3
closeCircleLine2:setStrokeColor(1)
closeCircleGrp:insert(closeCircle)
closeCircleGrp:insert(closeCircleLine1)
closeCircleGrp:insert(closeCircleLine2)
closeCircleGrp.closeCircle = closeCircle
return closeCircleGrp
end
L.onRowRender = function(event)
--Set up the localized variables to be passed via the event table
local row = event.row
local id = row.index
if event.row.params ~= nil and event.row.params.headerName ~= nil and id == 1 then
local params = event.row.params
local hdrTxt = (params.headerName or "header")
local headerTxt = display.newText( hdrTxt, row.contentWidth/2, row.contentHeight/2, fontName, fontSize )
headerTxt:setFillColor( 0 )
row:insert(headerTxt)
local closeCircleGrp = params.closeCircle
closeCircleGrp.x = row.contentWidth - row.contentHeight/2
closeCircleGrp.y = row.contentHeight/2
row:insert(closeCircleGrp)
--closeCircle:addEventListener( "touch", L.tableView.onCloseTouched )
else
if event.row.params ~= nil then
local params = event.row.params
local columnData = params.columnData
local columnWidthPercent = params.columnWidthPercent
local totalWidth = 0
for i, column in ipairs(columnData) do
local columnBox = display.newRect( totalWidth, row.contentHeight/2, row.contentWidth * columnWidthPercent[i], row.contentHeight * .98)
columnBox.strokeWidth = 2
columnBox:setStrokeColor(1, 1, 1, 0)
columnBox.anchorX = 0
columnBox:setFillColor( .4, .4, .4, 1 )
row:insert(columnBox)
local clmTxt = (columnData[i] or "NA")
if event.row.params.headerMultiLine == true then
local columnText = display.newText( clmTxt, columnBox.x + columnBox.contentWidth/2, columnBox.y, row.width * .90, row.height * .90, fontName, fontSize )
row:insert(columnText)
else
local columnText = display.newText( clmTxt, columnBox.x + columnBox.contentWidth/2, columnBox.y, fontName, fontSize )
row:insert(columnText)
end
totalWidth = totalWidth + columnBox.contentWidth
end
end
end
end
L.onRowTouch = function(event)
end
L.scrollListener = function(event)
end
L.AdjustSize = function()
rowStartingYPosition = display.contentHeight/10
rowHeight = display.contentHeight * .10
end
L.DisplayGrid = function(table, options, listerner)
local tableView = nil
if _W > _H then
L.AdjustSize()
end
local backgroundColor = {0.2, 0.2, 0.2}
if options.backgroundColor ~= nil then
backgroundColor = { (options.backgroundColor[1] or 0.4), (options.backgroundColor[2] or 0.4), (options.backgroundColor[3] or 0.4), (options.backgroundColor[4] or 0.5)}
end
local headerColor = { default={.5,.5,.5}, over={.5,.5,.5} }
if options.headerColor ~= nil then
headerColor = { default={ (options.headerColor[1] or .5),(options.headerColor[2] or .5),(options.headerColor[3] or .5)}, over={(options.headerColor[1] or .5),(options.headerColor[2] or .5),(options.headerColor[3] or .5)} }
end
local titleColor = { default={.5,.5,.5}, over={.5,.5,.5} }
if options.titleColor ~= nil then
headerColor = { default={ (options.titleColor[1] or .5),(options.titleColor[2] or .5),(options.titleColor[3] or .5)}, over={(options.titleColor[1] or .5),(options.titleColor[2] or .5),(options.titleColor[3] or .5)} }
end
tableView = widget.newTableView(
{
x = (options.x or display.contentWidth/2),
y = (options.y or display.contentHeight/2),
height = display.contentHeight * (options.gridHeight or .70),
width = display.contentWidth * (options.gridWidth or .80),
noLines = (options.noLines or true),
backgroundColor = backgroundColor,
onRowRender = L.onRowRender,
onRowTouch = L.onRowTouch,
listener = L.scrollListener
}
)
tableView.eventDispatcher = system.newEventDispatcher()
tableView.eventDispatcher:addEventListener("grid", listerner)
tableView.onCloseTouched = function(event)
if not (event.phase == "began") then
return
end
tableView = tableView:removeSelf()
tableView = nil
--print("++++++garbage:",math.floor(collectgarbage('count')))
end
if options.showTitle == true then
print("Options TitleHeight:", options.titleHeight)
local width = ((options.titleHeight or rowHeight) * .70)/2
local closeCircleGrp = L.createCircle(width)
closeCircleGrp:addEventListener( "touch", tableView.onCloseTouched )
tableView:insertRow {
rowHeight = (options.titleHeight or rowHeight),
isCategory = (options.isCategory or false),
rowColor = titleColor,
params = {
headerName = (options.titleName or ""),
closeCircle = closeCircleGrp
}
}
end
if options.showColumnHeader == true then
tableView:insertRow {
rowHeight = (options.headerHeight or rowHeight),
isCategory = (options.isCategory or true),
rowColor = headerColor,
params = {
columnData = options.columnDisplayName,
columnWidthPercent = options.columnWidthPercent,
headerMultiLine = (options.headerMultiLine or false)
}
}
end
if table ~= nil then
for i, entry in pairs(table) do
local userName = entry.userName
print("row:", i)
tableView:insertRow {
rowHeight = (options.rowHeight or rowHeight),
isCategory = false,
rowColor = headerColor,
params = {
columnData = L.createTableData(entry, options),
columnWidthPercent = options.columnWidthPercent
}
}
end
end
return tableView
end
L.init = function()
end
return L