Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Kolyunya on January 23, 2014, 04:53:32 AM

Title: UIFont.CalculatePrintedSize alternatives
Post by: Kolyunya on January 23, 2014, 04:53:32 AM
One of the latest NGUI updates broke my code which used UIFont.CalculatePrintedSize method.
What are the alternatives which are available in the latest release?
Why was the method removed?
Thank you for help!
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: ArenMook on January 23, 2014, 05:20:32 AM
It wasn't removed, it was moved to NGUIText.
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: Kolyunya on January 23, 2014, 06:16:07 AM
ArenMook, why doesn't this function depend on the particular font? Different fonts should produce different values, should not they?
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: ArenMook on January 23, 2014, 06:20:31 AM
Because you should call UILabel's UpdateNGUIText() prior to using NGUIText functions. It's what sets the font and everything else.
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: Zoidster on December 15, 2014, 06:59:55 AM
Digging out this old topic.
Can you tell me how I can calculate the width of a string in a label of a given font and fontsize (without writing my own CalculatePrintedSize method)?
I want to calculate the width to see if I have to add a linebreak.
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: ArenMook on December 15, 2014, 12:51:30 PM
Just use the existing CalculatePrintedSize. Why write your own? I don't quite understand the question. UpdateNGUIText() function sets everything NGUIText needs to work. If you want a different font size, just set it prior to calling CalculatePrintedSize -- NGUIText.fontSize = 32;
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: Zoidster on December 15, 2014, 12:54:28 PM
I'm going to try that first thing tomorrow. Thanks.
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: Zoidster on December 16, 2014, 06:16:48 AM
Ok, that works if I also adjust the rect size in nguitext. My problem was that I put the text in, then updated nguitext, and then calculated the size. The vector2 I got out of the calculation was not the size of the text as one row, but the size of the label.
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: ArenMook on December 17, 2014, 03:02:16 PM
Try posting the code you're using, it might help me understand what you're doing wrong.
Title: Re: UIFont.CalculatePrintedSize alternatives
Post by: Zoidster on December 18, 2014, 02:40:14 AM
Its working now, as I said.
This was my code before:
  1. label.text = myText;
  2. label.UpdateNGUIText();

The problem was that I wanted the width of "Example text" and the calc method gave me the width (and height) of
"Example
text"

That was, because my label wasn't wide enough for the text. Now that I added these lines
NGUIText.rectWidth = int.MaxValue;
NGUIText.rectHeight = int.MaxValue;

The method calculates the width of the text as one line rather than breaking it up into multiple lines.