Change text options.

Hi. Just started using Corona. Really love it but I have a question already :stuck_out_tongue:
I am able to do stuff like:

local options = {     parent = group,     text = text,     x = x,     y = y,     width = width,     height = height,     font = native.systemFontBold,     fontSize = 18,     align = "left" }   local txt = display.newText( options ) txt.text = "New String"

That will set the new text as expected.

However I am not able to do:

txt.fontSize = 1  

What am I missing here?

Thanks.

UPDATE

Managed to change the font size. I thought it was: text.fontSize, but it turns out its just text.size
But I am still unable to change the font itself. I have tried to do:

text.font = native.newFont( \_font )

But without luck. I cant figure out if it actually works after the text has been created or I need to set it when I create it in the options.

You can also pass it as a parameter to the display text objects in the display.newText() function.

Confuses me a little bit… - http://docs.coronalabs.com/api/library/native/newFont.html

  1. I didn’t know you could pass a table to display.newText(), so that’s pretty cool. (I see it’s a G2.0 change) So I assume you’re running a build in the 2000+ number.

  2. According to the docs it’s .fontSize, but if it’s not I suggest clicking the “Hate it” button at the bottom of the doc page and ask them to fix the doc page. Pre-graphics 2.0 you could change text size using .size.

  3. You can’t change the font of display.newText() objects once they are created; you can only change stuff like .text, the color, and positioning. At least, that’s how it used to work…

  4. The native.newFont() object does not seem particularly useful unless you are trying to make native text boxes; for most purposes you can just type the exact font name out (ie: “HelveticaNeue-Bold”) or use stuff like native.systemFont.

Thank you for that reply.

Hmm, so I guess I will have to destroy the text and recreate it when I want to change stuff like alignment and font.

I will give it a try after dinner and see how it works :slight_smile:

Hi @richard9 and @some12thing,

The ability to pass an “options” table to display.newText() has been around for awhile now. It’s commonly used when you need the alignment feature (i.e. a multi-line text block aligned right or center, versus left). Or, some developers prefer that style because it’s easier to see the parameters spelled out in their code.

See the documentation here:

http://docs.coronalabs.com/api/library/display/newText.html

As for the “.size” vs. “.fontSize” thing, it’s more of a semantics/syntax thing. If you’re using the options-table method, the size is dictated by the “fontSize” key-value pair when you create the text. If you’re using the legacy style, that value is just a number (it doesn’t get passed as a named parameter in that case). Post-creation, it should still be “.size” to change the font size.

@some12thing,

Size of the text can be changed post-creation, but not the font. “Alignment” for the entire “unit” of text (one line or multi-line) can be adjusted by re-positioning it post-creation, i.e. setting the anchor point to the left side and placing it along the theoretical vertical line/margin where you want it.

Hope this helps,

Brent Sorrentino

UPDATE

Managed to change the font size. I thought it was: text.fontSize, but it turns out its just text.size
But I am still unable to change the font itself. I have tried to do:

text.font = native.newFont( \_font )

But without luck. I cant figure out if it actually works after the text has been created or I need to set it when I create it in the options.

You can also pass it as a parameter to the display text objects in the display.newText() function.

Confuses me a little bit… - http://docs.coronalabs.com/api/library/native/newFont.html

  1. I didn’t know you could pass a table to display.newText(), so that’s pretty cool. (I see it’s a G2.0 change) So I assume you’re running a build in the 2000+ number.

  2. According to the docs it’s .fontSize, but if it’s not I suggest clicking the “Hate it” button at the bottom of the doc page and ask them to fix the doc page. Pre-graphics 2.0 you could change text size using .size.

  3. You can’t change the font of display.newText() objects once they are created; you can only change stuff like .text, the color, and positioning. At least, that’s how it used to work…

  4. The native.newFont() object does not seem particularly useful unless you are trying to make native text boxes; for most purposes you can just type the exact font name out (ie: “HelveticaNeue-Bold”) or use stuff like native.systemFont.

Thank you for that reply.

Hmm, so I guess I will have to destroy the text and recreate it when I want to change stuff like alignment and font.

I will give it a try after dinner and see how it works :slight_smile:

Hi @richard9 and @some12thing,

The ability to pass an “options” table to display.newText() has been around for awhile now. It’s commonly used when you need the alignment feature (i.e. a multi-line text block aligned right or center, versus left). Or, some developers prefer that style because it’s easier to see the parameters spelled out in their code.

See the documentation here:

http://docs.coronalabs.com/api/library/display/newText.html

As for the “.size” vs. “.fontSize” thing, it’s more of a semantics/syntax thing. If you’re using the options-table method, the size is dictated by the “fontSize” key-value pair when you create the text. If you’re using the legacy style, that value is just a number (it doesn’t get passed as a named parameter in that case). Post-creation, it should still be “.size” to change the font size.

@some12thing,

Size of the text can be changed post-creation, but not the font. “Alignment” for the entire “unit” of text (one line or multi-line) can be adjusted by re-positioning it post-creation, i.e. setting the anchor point to the left side and placing it along the theoretical vertical line/margin where you want it.

Hope this helps,

Brent Sorrentino