Please Verify: display.newText() multi-line text capable?

According to the notes in the Daily Builds for 2011.704 found here:

http://developer.anscamobile.com/content/corona-sdk-release-notes-build-2011704

The 12th bullet down the list says that in this new release:

* “display.newText supports multiline text”

Could some-one please verify if this is true?! I love ANSCA/Corona but the docs are driving me nuts. While this appears to work in the Windows Simulator, this does NOT work on my iOS devices or on the Mac Simulator. (Not using “\n” for a newline character, anyway.) There is NOTHING in the docs about this! Is this a bug or a typo?! If this feature is actually there, could you document it and/or make sure it works? Maybe specify that it only works for Android (if that is the case-- I can’t tell.)? If not, could you pull it from the list of features or correct it?

Seriously: these kinds of mistakes/omissions in the docs can cause hours/days of work/confusion for developers.

Grumble grumble mutter mutter you darn kids get offa my lawn and fix my docs grumble grumble shake fist at cola-drinkin’, rock-n-roll listenin’ hoodlums neighborhood all fallin’ apart no respect for documentation when I was a boy we ate documentation for breakfast… we recited documentation and if we got it wrong they’d cut off a finger… no respect, these kids these days grumble grumble… we had nothing but Pong and Timex Sinclairs and we learned to LIKE it…

[import]uid: 10818 topic_id: 18996 reply_id: 318996[/import]

Oh, Bother.

So, the docs still aren’t up-to-date, but after doing one more thorough scan of the release notes… there at the very bottom I spotted a tiny bit of information that answers my question:

[text]
iOS/Mac: for multiline text, display.newText() now supports variable height, the width must be supplied and height must be 0.
iOS/Mac: multiline text and support for newline character in display.newText( string, x, y, [w, h,] font, size ). You must supply the optional w,h params to enable multiline behavior; otherwise it reverts to single line. The w,h define the box in which the text is rendered.
[/text]

This should still be in the API docs, but there’s the answer for anyone who wants to know.

mutter mutter… [import]uid: 10818 topic_id: 18996 reply_id: 73139[/import]

Hey there,

I found your rant most amusing.

We know the docs need updating to reflect changes in the latest release - it’s on the to-do list.

Peach (the hoodlum in the santa hat) :slight_smile: [import]uid: 52491 topic_id: 18996 reply_id: 73150[/import]

@Peach-

Thanks, you Hoodlum!

I find that if I’m going to be grumpy about something, it is best to channel an old man in my psyche, and let him take over for a few minutes. (Then, quickly before I have a psychotic break, I must send the old man back to his tv with milk and cookies so I can continue to work.)

(Besides, this is a good warm up exercise for being 90 years old.)

:wink:

[import]uid: 10818 topic_id: 18996 reply_id: 73165[/import]

I certainly agree it is a much nicer approach than simply being grumpy - plus when milk (chocolate) and cookies are involved, all the better :wink: [import]uid: 52491 topic_id: 18996 reply_id: 73175[/import]

I am in the process of updating the documentation. By this I mean:

  1. Adding the new features to the api listings.
  2. Making the current api listings more comprehensive with clearer instructions and samples.

Thanks for your patience :slight_smile: [import]uid: 84637 topic_id: 18996 reply_id: 73185[/import]

Multiline text is great, however it not possible to justify the text (yet, i guess).

I have a small function that reads a line of text with embedded ‘\n’ characters and splits the text up into multiple text objects and returns a group with these objects. Also allowing the texts to be left-/center- or right justified.

Here’s an excerpt from my module code if anybody’s interested:

[lua]Module.ALIGN_LEFT = 0;
Module.ALIGN_CENTER = 1;
Module.ALIGN_RIGHT = 2;

Module.newText = function(str, xPos, yPos, font, size)
local scaleY = display.contentScaleY;
local scaleFactor = 1.0 / scaleY;
local text = display.newText(str, 0, 0, font, size * scaleFactor);

text.xScale, text.yScale = scaleY, scaleY;
text.x, text.y = xPos, yPos;

return text;
end

Module.newMultilineText = function(str, x, y, font, size, align, ref)
local tStr = str or “{empty}”;
local xPos = x or 0;
local yPos = y or 0;
local tFont = font or native.systemFont;
local tSize = size or 12;
local tAlign = align or Module.ALIGN_LEFT;
local tReference = display.CenterLeftReferencePoint;
local gReference = ref or display.CenterReferencePoint;
local textArray = {};

if (tAlign == Module.ALIGN_RIGHT) then
tReference = display.CenterRightReferencePoint;
elseif (tAlign == Module.ALIGN_CENTER) then
tReference = display.CenterReferencePoint;
end

local startPos = 1;
local yPosLine = 0;
local posLF = tStr:find(’\n’, startPos, true);

local addTextLine = function()
local newEntry = #textArray + 1;
textArray[newEntry] = Module.newText(tStr:sub(startPos,posLF), xPos, yPos, tFont, tSize);
textArray[newEntry]:setReferencePoint(tReference);
textArray[newEntry].x = 0;
textArray[newEntry].y = yPosLine;
end

while (posLF) do
addTextLine();
startPos = posLF + 1;
yPosLine = yPosLine + (textArray[#textArray].height * textArray[#textArray].yScale);
posLF = tStr:find(’\n’, startPos, true);
end

addTextLine();

local multiLine = display.newGroup();

for i=1, #textArray do
multiLine:insert(textArray[i]);
end

multiLine:setReferencePoint(gReference); – set group reference point
multiLine.x = xPos;
multiLine.y = yPos;

return multiLine;
end[/lua] [import]uid: 70847 topic_id: 18996 reply_id: 73191[/import]

Hey, @ingemar, this is cool. Thank you for sharing. I’ve bookmarked it for me to use in my next project.

Cheers,
Naomi [import]uid: 67217 topic_id: 18996 reply_id: 73284[/import]

bookmarked for future use, thanks ingemar [import]uid: 16142 topic_id: 18996 reply_id: 73293[/import]

@Ingemar: Nice little module!

I have been using something similar that does automatic line-wrapping. That was working great. But I’ve got an app that plays audio while the user scrolls through text… and when they scroll a bunch of text boxes (the lines) then the audio gets jittery. (Only on the 2nd gen iPod touch.) Might just be a tad too much processing power for the older device. I’m hoping the new display.newText mutli-line feature runs faster.

@Danny: Thanks!

@Peach: Mmmmm. Cookies. [import]uid: 10818 topic_id: 18996 reply_id: 73410[/import]

+1 on the need for text justification (left, center, right, full)
+1 on the need for setting width and height and autosizing the font

I think this is basic stuff critical to opening Corona to more business apps, and will definitely make everyone who diplays text have a much easier time.

I have been evaluating Corona SDK for about a month now, and I am really enjoying the good stuff. But little things like this make me want to rip my hair out!

Thanks for the hard work, I am hoping to hear if you have any info about this.

The closes I have found is this class, but its excruciatingly slow:
https://github.com/sunmils/corona_sdk_wrapper-class/blob/master/wrapper.lua [import]uid: 112147 topic_id: 18996 reply_id: 83007[/import]

Ok uh…I still didn’t subscribe for a paid developer account, as I’m still testing the features and learning corona / lua, so… just to make this clear, This is already available at the last free build, right?

I’m asking this because my code is running properly on the windows simulator, but whenever I try to put the app on my iphone / idevice simulator, the text just disappears.

I’ve tried several ways of typing the text, but I can’t seem to find the error.

Could you guys take a look at it and help me?
spent around 5 hours trying to sort this out, it looks great on the windows corona simulator, but only there…

resultadoTexto = display.newText(“testing”, 10, 280, 340, 0 )

above is the code where it gets first displayed, and then I have a function which changes the text when I click on a button.

The function is working fine, the texts get changed if there is a single line.

below is what I’m trying to display after button is clicked.

Cinquenta, sessenta, etc, are variable names of some calculations made and am trying to display the results.

[blockcode]resultadoTexto.text = “Faixas de treinamento: *”…"\n\n"…“Treino Leve / Aquecimento : “…cinquenta…” a “…sessenta…” bpm.\n”…“Queima de Gorduras : “…sessenta…” a “…setenta…” bpm.\n”…“Endurance / Resistência :”…setenta…" a “…oitenta…” bpm.\n"…“VO2 Máximo : “…oitenta…” a “…noventa…” bpm.\n”…“Esforço Máximo / Limite : “…noventa…” a “…freqMaxima…” bpm.”[/blockcode]
Tried putting it all between ( ) , tried separating the lines on the .lua file after the \n… , to help readability , tried putting it all on one single line. They all ran fine on corona emulator. No good on iphone simulator / physical iphone.
(well, I know that I’m gonna end up using more fields for proper alignment, but I really wanted to sort this thing out before moving on)

thanks!

(edit: will try one last build, reducind the number of concatenations and etc…)

 resultadoTexto.text = "Faixas de treinamento: \*\n\nTreino Leve / Aquecimento : "..cinquenta.." a "..sessenta.." bpm.\nQueima de Gorduras : "..sessenta.." a "..setenta.." bpm.\nEndurance / Resistência :"..setenta.." a "..oitenta.." bpm.\nVO2 Máximo : "..oitenta.." a "..noventa.." bpm.\nEsforço Máximo / Limite : "..noventa.." a "..freqMaxima.." bpm." 

display.newText is single line, you want display.newTextBox - see here; http://developer.anscamobile.com/reference/index/nativenewtextbox

Peach :slight_smile: [import]uid: 52491 topic_id: 18996 reply_id: 86559[/import]

@yamauti, @peach

Hey Peach! I think yamauti wants to use the display.newText instead of the native.newTextBox because native doesn’t give the same kind of freedom as the display objects. Corona display.newText was originally a single-line-only function, but as of build 704 it became multi-line. I know I had it working on a device using display.newText() a while back. Haven’t dabbled with it in a while. Is my understanding incorrect?

Yamauti-- If I have time today, i will run a test to make sure it works for me. What version/build of Corona are you using?

(The original grumpy old man.)
:wink: [import]uid: 10818 topic_id: 18996 reply_id: 86574[/import]

@peach,
Thanks for the quick reply, but the docs clearly state they are multiline as of .704, and the simulator is capable of reproducing them multiline…I know that I could use other tools to achieve my goals (and I’ll probably have to, as the layout gets broken when trying to align text like this) , but I really wanted to understand why it is not working, so that I properly learn about it for future projects :smiley:

@Duneunit,

I’m running corona 2011.704, I guess it is the exact build which allowed this. lol

Gonna run a couple more tests here and see what I can come up with.

Thanks !

[import]uid: 125498 topic_id: 18996 reply_id: 86642[/import]

My bad. I don’t know what was going through my mind when I wrote that - I was actually in the office when \n was fixed. (I was amazed how fast Walter did it, actually.)

Anyway, to correct what I said earlier;

[lua]local test = display.newText(“testing\ntesting”, 100, 100, 100, 100, native.systemFont, 12)[/lua]

That will work.

The difference between this and single line new text is that here you specify the width and height after X and Y.

Sorry Yamauti - and grumpy :wink:

Peach [import]uid: 52491 topic_id: 18996 reply_id: 86643[/import]

Don’t worry Peach =)

Hm, I’ve just made a test here, changing the “0” to “100”, for height, but I still have the same issue.

When I first instantiate my display.newText, the message appears just fine.

Then I click on the button which is supposed to change the .text property to that multiline monster thing I wrote, and it just disappears.

While running on the simulator it works fine, but not on my Iphone 2G.

I’m gonna run another test now, maybe trying to set the width and height after the text change, dunno… might be something similar to what happened with the X getting set off / reference point changing.

edit: no good. still doesn’t work.
Might be something on my huge string, will try to sort it out and let u guys know.

**edit2: Sorted it out!!

I tried getting all the special characters out of the code.
notice that on my big string there were some “ç” and “á”. (we use those a lot on brazilian portuguese).

without the special characters, it worked right away.**

Now, thing is. Can I set character encoding somehow, to be able to use those?
[import]uid: 125498 topic_id: 18996 reply_id: 86648[/import]

That’s interesting to know; unfortunately I don’t know off hand about this issue but I know another member of the team who is great with all this text stuff; am going to shoot him an email now and see what I can find out for you :slight_smile: [import]uid: 52491 topic_id: 18996 reply_id: 86779[/import]

Sweet =)

I believe this is gonna help a lot of people too, I’m advertising corona to all my dev friends as well…lol
thanks for all the help! [import]uid: 125498 topic_id: 18996 reply_id: 86782[/import]

Amazingly I just got a reply; it’s almost 10pm at Ansca HQ so that’s pretty impressive :wink:

He suggests that if the string is too long it will exceed the texture memory - the suggestion is that you try a short string using special characters and see whether or not that displays correctly.

Could you try this and let me know, please?

(As an added note, text and other display objects will disappear if antiAlias = true in config.lua and the object is rotated. This is a known bug.)

Peach :slight_smile: [import]uid: 52491 topic_id: 18996 reply_id: 86803[/import]