-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.lua
252 lines (185 loc) · 8.33 KB
/
list.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
241
242
243
244
245
246
247
248
249
250
251
252
local composer = require( "composer" )
local scene = composer.newScene()
local widget = require( "widget" )
local braintonikDialog = require "plugin.braintonik-dialog"
display.setStatusBar( display.HiddenStatusBar )
local json = require ("json")
-- decalre variable
local whichList = ""
-- find out where click originated
if gMenuItemSelection == 2 then
whichList = "entryLevel.json"
elseif gMenuItemSelection == 3 then
whichList = "enhanced.json"
elseif gMenuItemSelection == 4 then
whichList = "iot.json"
elseif gMenuItemSelection == 5 then
whichList = "wear.json"
elseif gMenuItemSelection == 6 then
whichList = "retired.json"
elseif gMenuItemSelection == 7 then
whichList = "shields.json"
elseif gMenuItemSelection == 8 then
whichList = "sensors.json"
end
--open file
local filePath = system.pathForFile ("database/"..whichList)
local file = io.open (filePath, "r") --open file as read only
local contents = file:read("*a") -- load contents into variable 'contents'
io.close(file) -- closes the file
local boardTable = json.decode (contents) -- decode the file into LUA table
-- for setting up eventlisteners to open info
local selectRect = {}
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
local globalFunc = require("globalFunc")
display.setDefault("fillColor", 0,0,0,1)
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
-- Test reading JSON ok
print (boardTable[1].NAME)
print (boardTable[1].MICROCONTROLLER)
print (#boardTable)
---------------------------------------------------------------------------------------------------------------
---------------------------------------CREATE SCROLL VIEW------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
-- ScrollView listener
local function scrollListener( event )
local phase = event.phase
if ( phase == "began" ) then print( "Scroll view was touched" )
elseif ( phase == "moved" ) then print( "Scroll view was moved" )
elseif ( phase == "ended" ) then print( "Scroll view was released" )
end
-- In the event a scroll limit is reached...
if ( event.limitReached ) then
if ( event.direction == "up" ) then print( "Reached bottom limit" )
elseif ( event.direction == "down" ) then print( "Reached top limit" )
elseif ( event.direction == "left" ) then print( "Reached right limit" )
elseif ( event.direction == "right" ) then print( "Reached left limit" )
end
end
return true
end
-- Create the widget
scrollView = widget.newScrollView(
{
-- top = 0,
--left = 0,
x = display.contentCenterX,
y = display.contentCenterY,
height = display.actualContentHeight,
width = display.actualContentWidth,
--scrollWidth = 600,
listener = scrollListener,
horizontalScrollDisabled = true,
backgroundColor = { 244/255,244/255,244/255 }
}
)
sceneGroup:insert (scrollView)
-------------------------------------END----------------------------------------------------
-- Function for list tap
local function listTap (event)
print ("Tap works")
tapSelection = event.target.selection
composer.gotoScene ("detailed",sceneOptions)
end
--build list
for i = 1, #boardTable do
local yPos = 50 + (i * 300)
selectRect[i] = display.newRect(sceneGroup,display.contentCenterX, yPos-110, display.actualContentWidth, 250 )
selectRect[i]:setFillColor( 244/255,244/255,244/255,1)
selectRect[i].anchorY = 0
scrollView:insert (selectRect[i])
selectRect[i].selection = i
selectRect[i]:addEventListener ("tap", listTap)
local nameText = display.newText (sceneGroup,boardTable[i].NAME,display.contentCenterX-80, yPos-90, "fonts/segoeuib.ttf",36)
nameText:setFillColor (0,0,0)
nameText.anchorX = 0
local digPinText = display.newText (scrollView,"Digital Pins:",display.contentCenterX-80, yPos-40, "fonts/segoeui.ttf",30)
local pwmPinText = display.newText (scrollView,"PWM Pins:",display.contentCenterX-80, yPos+10, "fonts/segoeui.ttf",30)
local analogPinText = display.newText (scrollView,"Analog Pins:",display.contentCenterX-80, yPos+60, "fonts/segoeui.ttf",30)
local flashMemText = display.newText (scrollView,"Flash Memory:",display.contentCenterX-80, yPos+110, "fonts/segoeui.ttf",30)
local digPinTextInfo = display.newText (scrollView,boardTable[i].DIGITALPINS,display.actualContentWidth-80, yPos-40, "fonts/segoeuil.ttf",30)
local pwmPinTextInfo = display.newText (scrollView,boardTable[i].PWMPINS,display.actualContentWidth-80, yPos+10, "fonts/segoeuil.ttf",30)
local analogPinTextInfo = display.newText (scrollView,boardTable[i].ANALOGPINS,display.actualContentWidth-80, yPos+60, "fonts/segoeuil.ttf",30)
local flashMemTextInfo = display.newText (scrollView,boardTable[i].FLASHMEM,display.actualContentWidth-80, yPos+110, "fonts/segoeuil.ttf",30)
digPinText.anchorX = 0
pwmPinText.anchorX = 0
analogPinText.anchorX = 0
flashMemText.anchorX = 0
digPinTextInfo.anchorX = 1
pwmPinTextInfo.anchorX = 1
analogPinTextInfo.anchorX = 1
flashMemTextInfo.anchorX = 1
local thumb = display.newImageRect (sceneGroup,boardTable[i].IMAGE..i..".jpg",520/2,330/2)
thumb.x = display.actualContentWidth * 0.2
thumb.y = yPos
local lineStart = display.actualContentWidth-50 --work out 50 from left edge
local line = display.newLine (sceneGroup,display.actualContentWidth - lineStart,yPos+160,display.actualContentWidth - 50,yPos+160)
line:setStrokeColor( 222/255,222/255,222/255, 1 )
line.strokeWidth = 4
scrollView:insert (digPinText)
scrollView:insert (pwmPinText)
scrollView:insert (analogPinText)
scrollView:insert (flashMemText)
scrollView:insert (digPinTextInfo)
scrollView:insert (pwmPinTextInfo)
scrollView:insert (analogPinTextInfo)
scrollView:insert (flashMemTextInfo)
scrollView:insert (nameText)
scrollView:insert (thumb)
scrollView:insert (line)
-- stockRectangle[i].selection = i
--stockRectangle[i]:addEventListener ("tap", openStockInfo)
i = i + 1
end
-- Load UI and insert into Scene Group
display.setDefault( "background", 244/255,244/255,244/255 )
globalFunc.createUI()
print (harry)
sceneGroup:insert (gHeaderRect)
sceneGroup:insert (gHeaderLogo)
sceneGroup:insert (gHeaderMenu)
gHeaderMenu:addEventListener ("tap", globalFunc.openMenu)
end
-- show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
end
end
-- hide()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
end
end
-- destroy()
function scene:destroy( event )
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return scene