Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started 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!
-
It wasn't removed, it was moved to NGUIText.
-
ArenMook, why doesn't this function depend on the particular font? Different fonts should produce different values, should not they?
-
Because you should call UILabel's UpdateNGUIText() prior to using NGUIText functions. It's what sets the font and everything else.
-
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.
-
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;
-
I'm going to try that first thing tomorrow. Thanks.
-
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.
-
Try posting the code you're using, it might help me understand what you're doing wrong.
-
Its working now, as I said.
This was my code before:
label.text = myText;
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.