Author Topic: Font Scale per UILabel  (Read 7108 times)

JeremyBurgess

  • Guest
Font Scale per UILabel
« on: October 08, 2013, 08:32:14 AM »
Hi all/ArenMook,

First our problem. Our artists have used many different font scales prior to NGUI 3.0.0 by setting scale to a value other than the line height of the font on UILabels in an existing project. This font is not a dynamic font, partly due to some in texture post-processing and partly due to font license issues preventing possible distribution of the TTF in question. When migrating to NGUI 3, all these scales got lost, as this feature is not supported (especially for widgets that are multi-line - single line widgets will obviously work just by setting a height and 'Shrink Content'). 

I'd just like to file a feature request really - the ability to specify a 'font scale' on a UI Label widget, in order to have a single font be scaled to fit multiple specific sizes on a per label basis. This is predominantly to assist in migration to NGUI 3.0.2.

Obviously there are ways around this for a new project:
 * Creating multiple font prefabs based on the same bitmap (for non-dynamic fonts) with different pixel sizes will achieve the same end.
 * Scaling widgets overall will also achieve this, but makes sizes confusing, and this also is non-desirable.
 * Dynamic fonts facilitate having as many font sizes as you like.

We've made the change in our copy of NGUI - it's pretty straightforward:
 * Add float mFontScale to UILabel.
 * Apply it by multiplying mFont.size by it when computing printSize in ProcessText.
 * Add inspector code for it in the UILabelInspector.

As I say - there are clearly ways around this, and I understand if the feature is deemed undesirable, but it's greatly smoothed over the process of migrating our project to NGUI 3.

Cheers,
Jeremy

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font Scale per UILabel
« Reply #1 on: October 09, 2013, 09:02:55 AM »
You can still adjust the scale of UILabels as you see fit. For example if you have a size 48 font, you can set the scale of the UILabel to be 0.5 all around, and it will effectively be drawn as a size 24 font (though naturally not as crisp as having a native size 24 font).

peter

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Font Scale per UILabel
« Reply #2 on: October 10, 2013, 06:24:47 AM »
We have a very similar issue. We use a big (hi-res) dynamic font and have created several menus with labels that scales the font down. This was done in NGUI 2.7. When upgrading to NGUI 3 (deleting all old NGUI files and adding the NGUI 3 files) all of our labels become very large. They are scaled up to the actual font size.

I will try to modify the UpgradeFrom265() function in UILabel to make it keep the original size. We have too many menus to do the scaling manually.
« Last Edit: October 10, 2013, 06:58:12 AM by peter »

JeremyBurgess

  • Guest
Re: Font Scale per UILabel
« Reply #3 on: October 10, 2013, 06:37:29 AM »
Hi ArenMook,

Yep - as I say I'm aware you can achieve the same result by scaling widgets overall to get a 'scaled' font, however this is non-desirable because it means the dimensions of the widget are no longer indicative of logical pixel size. Essentially to achieve a widget which is 400 px high and 600 px wide (logical - in UI Root relative space) I have to:
 1. Determine my font size. (Let's say 75% - will look OK if the font has Mips turned on).
 2. Create a widget which is 400 / 0.75 x 600 / 0.75.
 3. Scale it down to the desired dims.

It is much easier to tweak this kind of thing if I can set a desired widget size and a font scale of 0.75. One of the things I like best about NGUI 3 is the separation of dimensions and scale, I hate to have to have a special case for font scaling.

As I say, for future projects we'll get art to just determine the font set at the outset - it's easy enough to create pre-scaled fonts by duplicating the font prefab and using pixel size to get scaled versions thereof, it's just prohibitive for the project we've just ported.

Thanks!

peter

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Font Scale per UILabel
« Reply #4 on: October 10, 2013, 11:54:56 PM »
I made a patch to UILabel that keeps the scale on text when you upgrade from NGUI 2 to NGUI 3. It worked well for our purposes. PM me if you're interested in the patch.

ShinyMark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Font Scale per UILabel
« Reply #5 on: December 17, 2013, 02:33:29 PM »
We just upgraded from 2.7.0 to 3.0.7 and this change has caused a lot of visual problems for us as well. We are using bitmap fonts and want to set an explicit target glyph scale, like we used to be able to via the transform scale in 2.7.0.

Scaling the transform of the UILabel works but as JeremyBurgess said you then have to scale the size of the dimensions to compensate for it. This feels like a hack, especially after the push to hit a uniform 1 transform scale to allow NGUI widgets to be parented to one another, and it's something I'd prefer to avoid.

So +1 to re-adding this functionality as a property of UILabels for bitmap fonts. We love the new UILabel functionality but losing this is causing us a large amount of rework to address it in our project.