Title: Re: Calculate text width for a label
Post by: Sobraj on October 08, 2014, 07:03:23 AM
It does some weird things on my end.
My label has a width of 650 and has shrinkContent when I have a string which is clearly larger than the label can contain without resizing, it gives me a x value of 642. If I put my label on clamp it does the same, and when I put it on resize freely it says it is 270.
Am I missing something?
Title: Re: Calculate text width for a label
Post by: ArenMook on October 08, 2014, 01:28:41 PM
You need to turn off Shrink Content before doing this, otherwise it won't resize.
Title: Re: Calculate text width for a label
Post by: Sobraj on October 09, 2014, 05:56:52 AM
When I put it on freely resize it says it is 270 wide, while it clearly is way more then 650.
Title: Re: Calculate text width for a label
Post by: ArenMook on October 10, 2014, 02:22:54 AM
Let me rephrase... you need to change the label to Resize Freely prior to calling NGUIText.Update.
You can also forego the whole NGUIText thing just by simply doing this:
What I typically do in Windward (for tooltips and such) is do a check -- is the printedSize.x less or greater than a specified value? if so, then I set the label's width and change the overflow method to Resize Height instead of Resize Freely.
Title: Re: Calculate text width for a label
Post by: Sobraj on October 14, 2014, 02:23:19 AM
My label was on resize freely prior the call to UpdateNGUIText.
I used the code you supplied in your last post, works like a charm. Thanks for your help.
Title: Re: Calculate text width for a label
Post by: cayou on June 17, 2015, 09:43:01 AM
Yeah, I don't get it how you can calculate the size of the label with a static method (NGUIText.CalculatePrintedSize), how does the system know all the settings on your label? I'm VERY curious about that. It must takes into acount the current font, the font size, the spacing of the label, etc... Calling this method for me results in very weird results too. But still, the printedSize accessor of the UILabel makes a lot more sense.
Title: Re: Calculate text width for a label
Post by: ArenMook on June 18, 2015, 07:48:58 AM
UILabel.UpdateNGUIText()
Title: Re: Calculate text width for a label
Post by: cayou on June 18, 2015, 03:41:40 PM
Does the combo "myLabel.UpdateNGUIText + NGUIText.CalculatePrintedSize" make the same result as "myLabel.printedSize" ?
Title: Re: Calculate text width for a label
Post by: ArenMook on June 21, 2015, 06:25:48 PM
printedSize results in a call to ProcessText() which does more than setting NGUIText. It handles resizing of the label as well, for example.
Title: Re: Calculate text width for a label
Post by: bandingyue on June 01, 2016, 09:59:53 PM
I think maybe you should add a param to this function,a int param of lable`s size.
sometimes it is unconvinent to use label.UpdateNGUIText before.