Text wraps inconsistently on simulator and device

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

The text entry is something that we're still working on. Right now, '\n' only works in the simulator, which is why I think your device looks wrong. I think all of your text is ending up in that square, thus why its all white. There isn't really a good work around at the moment, short of loading text as a png image. Suffice to say, this is very high on our priority list and will be in a future release that should be available soon.

Thanks, Jeff. I'm looking forward to having text wrapping support. I'm trying to build an app that loads an XML file. It's a pretty text-heavy app.

By the way, I created a wrapping function that seems to work pretty well. I posted it here:

http://developer.anscamobile.com/forum/2009/12/27/multiline-text#comment-533

Maybe you can tell me why display.newText() chokes on invisible bad characters at the beginning of new lines?

Cheers,
GG

What characters are they, or rather what key combination generates them?

So I discovered that I'm having problems with the display.newText() function because I have extra line breaks at the beginning of some pieces of text. I'm having a hard time getting rid of them. It would be nice if display.newText() just ignored line breaks that appeared before any actual text.

While killing some time before partying for New Year's Eve, I was able to figure out my line break problem. I'm using PHP to pump out my XML file, so I str_replace()'ed all my "\r" to "\n" and then used trim() to remove the excess that might appear at the beginning or ending of text.

And I improved my text wrapping function to better support paragraphs, or multiple line breaks that appear within the text.

Take a look:

http://developer.anscamobile.com/forum/2009/12/27/multiline-text#comment-539

Thanks,
GG

I dont get it:
Is it still not fixed???

views:1590 update:2011/11/26 9:01:35
corona forums © 2003-2011