Can't Change Wrapping Width of display.newText( ) Object

I tried your code, and something interesting happened:

It did force the text object to regenerate, but to the wrong width!

Instead of forcing it to regenerate to the new, intended width, I just went right back to the old, original width.

(In my little example, this would mean the new width would be 100, the same as the original, instead of the intended 80)

FYI, remember text is just a bitmap object.  Easy fix - just drop  myText  and recreate on a text change.  

I assume that behind the scenes that is what Corona should be doing anyway but if Corona is trimming the string then adding a space might make no difference.

What exactly do you mean by “drop” the ‘myText’ object? Do you mean destroying it and creating a new one from scratch?

Yes, drop and recreate on a change of width.  It will be the same cost as telling Corona to change the text anyway.

It will sort your problems instantly.

@SGS

That worked, but it doesn’t really answering the question “how to change the width of a text object after creating it”.

I tried collectgarbage("count) and, contrary to what you said, it is much more expensive than say changing the .x or .size property of a text object. (makes sense since you are creating an entirely new object). Moreover, it takes up many more lines of code than should be necessary, and it is just god damn ugly code.

I am both extremely shocked and disappointed to learn that there is no way to do this like the way you would change the location or font size.

There is no excuse for the Corona team not to include such simple and obvious functionality.

They should include this in a future build, or if not at the very least, should mention this in the gotcha clause in https://docs.coronalabs.com/api/library/display/newText.html

I only try and help with solutions to problems… I cannot address the problems as I am not Corona.

@SGS
My criticism was not aimed at you. I was trying to reach out to the Corona team

Rendering text is an expensive operation. We have to take your string, pass various font information to the system’s API (which is different for each OS) and create a texture and a mask and return that rectangle back to OpenGL as a graphic texture.

When you change .text it should force the whole rendering process to fire. Replacing the text with the same text likely has a safety to prevent the text from re-rendering, which is why I suggested what I did above.

Still, the problem is the width. Since your working with an image in OpenGL changing .width probably just changes the texture width and doesn’t trigger a re-rendering. The width you pass in is a parameter and it doesn’t actually represent the width of the object, just the value we tell the OS text renderer to return.

That’s why I was hoping changing the text would force a re-render.

For us to address this we need a small demo project that we can run and see the problem. This includes a main.lua, config.lua, build.settings any font’s you’re using that’s not standard, and any other assets what we can unzip, point the simulator to it  and see the problem (or build for device and see the problem.

Compress this project into a .zip file (please try and avoid other compressions, like RAR) and fill out a bug report here:

https://portal.coronalabs.com/bug-submission

Thanks

Rob

@Rob Miracle

Ok, I will find the time to do so. Thanks for responding.