Created
October 13, 2013 03:24
-
-
Save rockitude/6957788 to your computer and use it in GitHub Desktop.
Corona TableView: My Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------------------------------------------------------------------- | |
-- | |
-- main.lua | |
-- | |
----------------------------------------------------------------------------------------- | |
local widget = require "widget" | |
display.setStatusBar(display.HiddenStatusBar) | |
local availableSections = {"Intro", "Verse", "Chorus", "Verse", "Chorus", "Interlude", "Breakdown", "Verse", "Chorus", "Outro"} | |
--listen for tableView press events | |
local function tableViewListener( event ) | |
local phase = event.phase | |
local row = event.target | |
print(event.phase) | |
end | |
--render rows | |
local function onRowRender( event ) | |
local phase = event.phase | |
local row = event.row | |
local rowTitle = display.newText(availableSections[row.index], 0, 0, system.nativeFont, 24) | |
rowTitle.x = row.x - (row.contentWidth * 0.5) + (rowTitle.contentWidth * 0.5) + 30 | |
rowTitle.y = row.contentHeight * 0.5 | |
rowTitle:setTextColor(1, 1, 1) | |
end | |
--handle row touches | |
local function onRowTouch( event ) | |
local phase = event.phase | |
local row = event.target | |
print("Row " .. row.index .. " touched.") | |
if phase == "press" then | |
print("Touched row:", event.target.index) | |
end | |
end | |
-- Create a tableView | |
local list = widget.newTableView | |
{ | |
width = display.contentWidth, | |
height = display.contentHeight, | |
--maskFile = "mask-410.png", | |
listener = tableViewListener, | |
onRowRender = onRowRender, | |
onRowTouch = onRowTouch, | |
} | |
-- Create rows | |
for i = 1, table.getn(availableSections) do | |
local isCategory = false | |
local rowHeight = display.contentHeight/table.getn(availableSections) | |
local rowColor = | |
{ | |
default = { 255, 255, 255 }, | |
} | |
local lineColor = { 220, 220, 220 } | |
-- Insert the row into the tableView | |
list:insertRow | |
{ | |
isCategory = isCategory, | |
rowHeight = rowHeight, | |
rowColor = rowColor, | |
lineColor = lineColor, | |
} | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment