How to print text in 3 columns

I am fairly new with LUA/Corona so I can’t get the logic just yet.

I have data that look like this (but the list is created dynamically):

cat
dog
egg
want
gone
bone
goner
bones
effort
effect
But I want it to look like this on-screen (notice that the list is arranged by number of letters):

cat gone effort
dog bone effect
egg goner
want bones
The list can be longer or shorter, but I wish to keep it at 3 columns. How can I do this?

Regards,

John [import]uid: 177058 topic_id: 31025 reply_id: 331025[/import]

How many items you want in one column ?
The limit will be in number of items or in height ?
[lua]local items = { }
items[1] = “cat”
items[2] = “dog”
items[3] = “egg”
items[4] = “want”
items[5] = “gone”
items[6] = “bone”
items[7] = “goner”
items[8] = “bones”
items[9] = “effort”
items[10] = “effect”

local fontSize = 16
local itemTemp = display.newText( “H”, 0, 0, native.systemFont, fontSize )
local itemHeight = itemTemp.height
itemTemp:removeSelf()
local columnHeight = display.contentHeight
local columnWidth = display.contentWidth / 3
local columnX= { }
columnX[1] = 0
columnX[2] = columnWidth * 1
columnX[3] = columnWidth * 2
local top = 0 --y position where to start
local deltaY = top

local j = 1
for i=1, #items, 1 do
if(deltaY + itemHeight < columnHeight) then
local item = display.newText( items[i], columnX[i], deltaY, native.systemFont, fontSize )
deltaY = deltaY + itemHeight
else
– next column
deltaY = top
j = j + 1
end
end[/lua]
I don’t test it but should work. You can optimise the code for your need. [import]uid: 138389 topic_id: 31025 reply_id: 124055[/import]

How many items you want in one column ?
The limit will be in number of items or in height ?
[lua]local items = { }
items[1] = “cat”
items[2] = “dog”
items[3] = “egg”
items[4] = “want”
items[5] = “gone”
items[6] = “bone”
items[7] = “goner”
items[8] = “bones”
items[9] = “effort”
items[10] = “effect”

local fontSize = 16
local itemTemp = display.newText( “H”, 0, 0, native.systemFont, fontSize )
local itemHeight = itemTemp.height
itemTemp:removeSelf()
local columnHeight = display.contentHeight
local columnWidth = display.contentWidth / 3
local columnX= { }
columnX[1] = 0
columnX[2] = columnWidth * 1
columnX[3] = columnWidth * 2
local top = 0 --y position where to start
local deltaY = top

local j = 1
for i=1, #items, 1 do
if(deltaY + itemHeight < columnHeight) then
local item = display.newText( items[i], columnX[i], deltaY, native.systemFont, fontSize )
deltaY = deltaY + itemHeight
else
– next column
deltaY = top
j = j + 1
end
end[/lua]
I don’t test it but should work. You can optimise the code for your need. [import]uid: 138389 topic_id: 31025 reply_id: 124055[/import]