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:

http://i133.photobucket.com/albums/q43/chiliberto_photos/Screenshot2009-12-29at112450AM.png

Device:

http://i133.photobucket.com/albums/q43/chiliberto_photos/Screenshot20091229112804.png
[import]uid: 3800 topic_id: 340 reply_id: 300340[/import]

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. [import]uid: 5 topic_id: 340 reply_id: 528[/import]

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 [import]uid: 3800 topic_id: 340 reply_id: 534[/import]

What characters are they, or rather what key combination generates them? [import]uid: 5 topic_id: 340 reply_id: 535[/import]

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. [import]uid: 3800 topic_id: 340 reply_id: 538[/import]

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 [import]uid: 3800 topic_id: 340 reply_id: 540[/import]

I dont get it:
Is it still not fixed??? [import]uid: 90911 topic_id: 340 reply_id: 69373[/import]

efgames, if you are experiencing issues they are likely very different to this issues from this (incredibly old) thread.

Please make a post describing the issues you are having in detail with steps to reproduce.

Peach :slight_smile: [import]uid: 52491 topic_id: 340 reply_id: 69541[/import]

Hey Peach,
yes, i have noticed that this issue was in Corona.

And i still have it!

Corona Lastest daily build,
when i using text like : ‘Test\nText’
In CoronaWin - its works as ‘Wrap’, in CoronaMac, and on device it dosent. It just ignored =(

what i`m doing wrong? what else should i submit? code:
local tfDescript = display.newText( ‘’, 100, 100, fontMain, 20 );
descriptHull = “Strong hull allows to endure\nmore collisions.”; [import]uid: 90911 topic_id: 340 reply_id: 69545[/import]

For using \n for multiline text you should be using display.newTextBox() and NOT display.newText.

See here; http://developer.anscamobile.com/reference/index/nativenewtextbox

Peach :slight_smile:

[import]uid: 52491 topic_id: 340 reply_id: 69635[/import]

Tnx!
Would be cool if you could add this info in your docs for http://developer.anscamobile.com/content/text-display-objects =) [import]uid: 90911 topic_id: 340 reply_id: 69693[/import]

Will bring that up in our next meeting. (We know the docs need some work.)

Peach :slight_smile: [import]uid: 52491 topic_id: 340 reply_id: 69759[/import]

Hey Peach,

The new native.newTextBox() seems to be quite different, UI wise, than the display.newText(). There’s doesn’t appear to be a way to hide the scrollbar, nor am I able to get rid of the shadow effect on the box. I tried setting the property “hasBackground” to false and that didn’t remove it. setTextColor() is also not working correctly, at least in the simulator.

With all this in mind, I’m unsure how I can display simple text that can scale well across different devices since I can’t bound the space it is to be displayed in with display.newText() & native.newTextBox() appears to be primarily for text entry.

Any tips would be most appreciated!

Thanks!

Scott D Brooks [import]uid: 63276 topic_id: 340 reply_id: 72126[/import]

Ummmm, I think this might be closer to what you are looking for - http://blog.anscamobile.com/2011/10/multiple-lines-in-display-newtext/

Let me know how that one goes.

Peach :slight_smile: [import]uid: 52491 topic_id: 340 reply_id: 72139[/import]

I want line-height for my text. because it too close together. Please talking that how do I have do [import]uid: 114484 topic_id: 340 reply_id: 91626[/import]

animals you cannot space out the lines, that depends on text size. You can get the height of a text block though. [import]uid: 52491 topic_id: 340 reply_id: 91658[/import]