I have a handy function to wrap text. It inserts a line breaks in the text.
On the simulator it works great. On the device the text either disappears after the first break or with long text it turns into a white stripe. My code and screenshots are below.
It would be a great way to wrap text if this could actually work on the device.
Thanks,
GG
-----8<-------------------------
local t1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc euismod justo sapien, at sollicitudin lacus."
local t2 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc euismod justo sapien, at sollicitudin lacus. Quisque vestibulum commodo felis id posuere. Vivamus lorem nisl, lacinia vel auctor at, interdum eget eros. Suspendisse interdum est in erat sodales rutrum interdum nulla convallis. Integer tincidunt purus ut dui sollicitudin tempus. Nunc orci mi, gravida non vulputate vel, gravida quis lorem. Praesent vel neque at ipsum elementum feugiat. Quisque vel sapien non sapien porttitor rutrum. Vestibulum consectetur quam at leo iaculis ultricies. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce mollis turpis in leo fermentum ornare."
function wrap(str, limit, indent, indent1)
indent = indent or ""
indent1 = indent1 or indent
limit = limit or 72
local here = 1-#indent1
return indent1..str:gsub("(%s+)()(%S+)()",
function(sp, st, word, fi)
if fi-here > limit then
here = st - #indent
return "\n"..indent..word
end
end)
end
t1 = wrap(t1, 48);
t1 = display.newText( t1, 12, 20, 0, 12 )
t1:setTextColor( 255, 255, 255 )
t2 = wrap(t2, 48);
t2 = display.newText( t2, 12, 144, 0, 12 )
t2:setTextColor( 255, 255, 255 )
-----8<-------------------------
Simulator:
[IMG]http://i133.photobucket.com/albums/q43/chiliberto_photos/Screenshot2009-12-29at112450AM.png[/IMG]
http://i133.photobucket.com/albums/q43/chiliberto_photos/Screenshot2009-12-29at112450AM.png
Device:
[IMG]http://i133.photobucket.com/albums/q43/chiliberto_photos/Screenshot20091229112804.png[/IMG]
http://i133.photobucket.com/albums/q43/chiliberto_photos/Screenshot20091229112804.png