Newline (\n) messing alignment

Hello!

When using display.newText() multiline, the \n character is messing with center align like it occupies its own space.

Please see attachment:

Is this normal? It even happens with the multiline example in http://coronalabs.com/blog/2014/02/11/tutorial-methods-for-positioning-text/.

 local save\_text = display.newText( { parent = sceneGroup, text = "12321\n45654\n78987", x = display.contentCenterX, y = 520, width = 500, height = 0, font = M.defaultFont, fontSize = 80, align = "center", } );

Looks like a bug. Guess you’ll have to do some horrible workaround, like making multiple text objects, or inserting whitespace in front of each line :expressionless:

Hi @zalacans,

I tested your exact code (copied from your post), and there is no issue for me. The text aligns perfectly. See the screenshot below.

I think your issue is that your “width” parameter is too low, and it’s forcing a weird wrap. With center alignment, width becomes somewhat pointless, as you could have a theoretical text box which is 500px or 5000px, and the text would still be in the center. So, try increasing that and see what happens.

Take care,

Brent

Well Brent, apparently it works fine on my device too!

Maybe only a simulator issue?

Looks like a bug. Guess you’ll have to do some horrible workaround, like making multiple text objects, or inserting whitespace in front of each line :expressionless:

Hi @zalacans,

I tested your exact code (copied from your post), and there is no issue for me. The text aligns perfectly. See the screenshot below.

I think your issue is that your “width” parameter is too low, and it’s forcing a weird wrap. With center alignment, width becomes somewhat pointless, as you could have a theoretical text box which is 500px or 5000px, and the text would still be in the center. So, try increasing that and see what happens.

Take care,

Brent

Well Brent, apparently it works fine on my device too!

Maybe only a simulator issue?