Author Topic: Shrink to Fit bug  (Read 6258 times)

hmnyari

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 29
    • View Profile
Shrink to Fit bug
« on: June 13, 2013, 03:38:53 AM »
updated 2.5.1 ->2.6.2

my dynamic font size is 36

 [shrink to fit :ON] and [Max width:80] write in UILabel. "abcdefg"

font size became small (36->24)

but when I delete my word to "abc", font size is not change.

font is not grow up to 36 automatically.

and MaxLine is ignored

Is this a bug?   

It was perfect when 2.5.1

look at this video please because I'm not good at English ;;
http://www.youtube.com/watch?v=__ALWFN_XZs


« Last Edit: June 13, 2013, 03:57:59 AM by hmnyari »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Shrink to Fit bug
« Reply #1 on: June 13, 2013, 04:23:08 AM »
Change UILabel.text to this:
  1.         public string text
  2.         {
  3.                 get
  4.                 {
  5.                         return mText;
  6.                 }
  7.                 set
  8.                 {
  9.                         if (string.IsNullOrEmpty(value))
  10.                         {
  11.                                 if (!string.IsNullOrEmpty(mText))
  12.                                         mText = "";
  13.                                 hasChanged = true;
  14.                         }
  15.                         else if (mText != value)
  16.                         {
  17.                                 mText = value;
  18.                                 hasChanged = true;
  19.                                
  20.                                 if (shrinkToFit)
  21.                                 {
  22.                                         MakePixelPerfect();
  23.                                         ProcessText();
  24.                                 }
  25.                         }
  26.                 }
  27.         }

hmnyari

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Shrink to Fit bug
« Reply #2 on: June 13, 2013, 06:04:34 AM »
Change UILabel.text to this:
  1.         public string text
  2.         {
  3.                 get
  4.                 {
  5.                         return mText;
  6.                 }
  7.                 set
  8.                 {
  9.                         if (string.IsNullOrEmpty(value))
  10.                         {
  11.                                 if (!string.IsNullOrEmpty(mText))
  12.                                         mText = "";
  13.                                 hasChanged = true;
  14.                         }
  15.                         else if (mText != value)
  16.                         {
  17.                                 mText = value;
  18.                                 hasChanged = true;
  19.                                
  20.                                 if (shrinkToFit)
  21.                                 {
  22.                                         MakePixelPerfect();
  23.                                         ProcessText();
  24.                                 }
  25.                         }
  26.                 }
  27.         }

Thank you so much for answer me  :D

Do you plan to apply this to the next version?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Shrink to Fit bug
« Reply #3 on: June 13, 2013, 02:11:42 PM »
It's already in the Professional repository, so yes.

robq

  • Guest
Re: Shrink to Fit bug
« Reply #4 on: June 17, 2013, 03:48:35 PM »
After applying this fix, there is still an issue when you first run the game, The text does not go to the size that it will go to after a change is made.

Using NGUI localization component on a UILabel game object, and switching from, for example, english to french, then back to english.

The english version, the 2nd time, is inconsistent with how it looks originally. Even though the text is the exactly same.

The only solution i have found so far is to put in UILocalize.cs, in Method Localize(), on line 68:

  1. if (input != null && input.label == lbl) input.defaultText = val;
  2. else lbl.text = val;
To be replaced by:
  1. lbl.MakePixelPerfect();
  2. if (input != null && input.label == lbl) input.defaultText = val;
  3. else lbl.text = val;
  4. lbl.text = lbl.processedText;

In that exact order. Moving MakePixelPerfect after setting the text, would cause it to ignore Max Width on the UILabel component.

robq

  • Guest
Re: Shrink to Fit bug
« Reply #5 on: June 17, 2013, 04:53:03 PM »
As a side note, it would be great to set a Maximum font size, for Shrink To Fit to use, as part of the UILabel component.

When it goes from a smaller text size to a bigger text size, it tends to take up a ton of room and look a little off compared to what would normally be manually set.

robq

  • Guest
Re: Shrink to Fit bug
« Reply #6 on: June 19, 2013, 12:44:57 PM »
Even after both fixes there seems to be some oddities, anyone else have solutions for the issue?

hmnyari

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Shrink to Fit bug
« Reply #7 on: June 19, 2013, 10:27:31 PM »
I found a perfect solution

1.Copy UILabel.cs at your previous version of NGUI (not 2.6.x)

2.paste it.

3.enjoy :)