Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: catbert on July 02, 2013, 02:20:24 AM

Title: Shrink to fit of UILabel
Post by: catbert on July 02, 2013, 02:20:24 AM
Hello.

for example,
font size is 32.
and I want to print some text by this font already scale to 16, (maxwidth is xxx, maxline is 1)
shrink to fit doesn't work.
It prints 2 lines because ProcessText() float maxY is 32.
Is it an intended behavior?

Thank you.
Title: Re: Shrink to fit of UILabel
Post by: ArenMook on July 02, 2013, 11:20:08 AM
Yes it's the intended behaviour because the shrunk text fits in the maximum Y size defined by your max lines (which is 32 pixels).
Title: Re: Shrink to fit of UILabel
Post by: catbert on July 02, 2013, 11:51:42 AM
I'm using 1 font(in this case 32 pixels font) to many sizes (scale to 10 20 30 40~),
in my example I scaled it to 16(x=16, y=16) and line count is 1.
so I want maxY is 16.
but ProcessText() maxY = mFont.size * mMaxLineCount; dependent on font size.
It means if I want to use shrink to fit works well, UILabel's scale must be same as font size.
Is this right?

Thank you.
Title: Re: Shrink to fit of UILabel
Post by: ArenMook on July 03, 2013, 06:15:25 AM
If you do that much scaling, I don't recommend using the "shrink to fit" option at all. I'd suggest having different size fonts as it will look much better.
Title: Re: Shrink to fit of UILabel
Post by: robq on July 03, 2013, 02:37:26 PM
I had to apply the fix for this issue in 2 places. When using Localization (im sure any run time text change would cause this as well)
Those 2 fixes are posted here:
http://www.tasharen.com/forum/index.php?topic=4627.msg22600#msg22600

and then an issue occurred where i was not able to get the font to the correct size consistently with whats in the editor, and, it wasnt obeying the "line" limit in one of ngui's calculations, and forced the very last letter of the sentence to the next line.

A 3rd temporary solution for me was

In ProcessText() method, replace the following line
  1. float maxY = (mFont.size * mMaxLineCount);
  2.  
With the code below
  1. float maxY = (mFont.size * mMaxLineCount);
  2. if (mShrinkToFit) // Fix to help labels fit into 1 line, when told to only be 1 line
  3. {
  4.         maxY = (mFont.size * mMaxLineCount) - 10;
  5. }
  6.  

This also corrects the size, after the previous 2 fixes. so that it is consistent with what you see in the editor, even with localization changing the text at runtime.

It's an issue that has to be solved from the ground up. Also. more checks on Line Limits, so that its impossible to have it ignore the line limit are needed.