Author Topic: Bug with UILabel "adjust scale to fit"  (Read 6874 times)

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Bug with UILabel "adjust scale to fit"
« on: August 12, 2013, 07:27:38 AM »
I am setting up my game so that there are two different sizes of each font, and using a reference font that gets set to one of the sizes, depending on what resolution the game is being run in (on a mobile device).

This works great, except that the "adjust scale to fit" feature seems to ignore the pixel size value of the current font. It seems to scale the label based on a pixel size of 1, no matter what it is set to.

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Re: Bug with UILabel "adjust scale to fit"
« Reply #1 on: August 12, 2013, 07:41:10 AM »
Changing lines of UILabel seems to have fixed it:

line 494
old:
float maxY = mFont.size * mMaxLineCount;

new:
float maxY = mFont.size * mMaxLineCount * mFont.pixelSize;

Add this line right after "if (mShrinkToFit)":
mSize.x /= mFont.pixelSize;

Also, this helps in the font setter, after everything else. Most other property setters have this call, so I'm not sure why the font setter doesn't:
if (shrinkToFit) MakePixelPerfect();
« Last Edit: August 12, 2013, 09:07:25 AM by Gillissie »

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Re: Bug with UILabel "adjust scale to fit"
« Reply #2 on: August 12, 2013, 07:46:07 AM »
On a related note, I have also changed line 652 of UILabel to take the font's pixel size into account when doing the effects...

old
float pixel =  1f / mFont.size;

new:
float pixel =  1f / mFont.size / mFont.pixelSize;

It would be great to see these changes in future versions out of the box. Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug with UILabel "adjust scale to fit"
« Reply #3 on: August 12, 2013, 03:57:58 PM »
Your suggestions make sense, however I am not quite clear where that is supposed to go:
Quote
Add this line right after "if (mShrinkToFit)":
mSize.x /= mFont.pixelSize;

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Re: Bug with UILabel "adjust scale to fit"
« Reply #4 on: August 12, 2013, 05:54:38 PM »
It's where the code with this comment is:

  1. if (mShrinkToFit)
  2. {
  3.         // We want to shrink the label (when it doesn't fit)
  4.         mSize.x /= mFont.pixelSize;     // Gillissie added
  5.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug with UILabel "adjust scale to fit"
« Reply #5 on: August 13, 2013, 08:28:07 PM »
Ok, I'll have a look at it again -- and I got your email too, thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug with UILabel "adjust scale to fit"
« Reply #6 on: August 13, 2013, 09:18:24 PM »
Alright, so I looked into it... first of all it makes sense to have that operation happen on the entire vector2, not just the X component. Second, seems to be that it should be a multiplication, not a division.