Author Topic: Anchoring labels with same fontsize for different screen sizes  (Read 4325 times)

eadwine

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Hello there :) This is my first project with NGUI and I'm really enjoying it so far!

I have a little trouble however with anchoring labels the right way so the font sizes will stay the same on different screen sizes.
For example I have 3 buttons next to eachother with each a label attached. The way I've done it so far is put the overflow on ShrinkContent and the fontsize to 40, so that on a big screen the text will still keep its proportions. I've anchored the labels in a way that really hugs the text inside of it.
When i resize the screen however, it can happen that one of the texts increase in size before the rest. This looks pretty bad especially when these buttons are so close you can easily compare them.

Is there an easier or better way to get this working correctly?

eadwine

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Anchoring labels with same fontsize for different screen sizes
« Reply #1 on: July 24, 2014, 09:41:49 AM »
Lol I found out it works perfectly when I don't anchor the labels at all   :)

EDIT  :( Seems that doesn't work for everything.... If anyone has a solution please let me know.
« Last Edit: July 24, 2014, 12:59:13 PM by eadwine »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Anchoring labels with same fontsize for different screen sizes
« Reply #2 on: July 25, 2014, 01:30:39 AM »
When did you set your anchors to update? If it's in OnUpdate, then they will be updated every frame. If it's OnEnable, then it will only happen once. A pic of your UI and inspector for the labels in question would help btw.

eadwine

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Anchoring labels with same fontsize for different screen sizes
« Reply #3 on: July 25, 2014, 05:59:08 AM »
The anchors are all updated in OnUpdate. I'll add a picture showing 2 examples of my problem, the view in scene mode and the inspector settings.



Theres only a minor difference in de text size, but it's noticable when they are so close together.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Anchoring labels with same fontsize for different screen sizes
« Reply #4 on: July 26, 2014, 12:23:14 AM »
You have them all set to "Shrink content", meaning if the text doesn't fit, the font's size will be decreased until it does.

You need to enlarge the label areas so that the text can fit.

eadwine

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Anchoring labels with same fontsize for different screen sizes
« Reply #5 on: July 31, 2014, 06:00:55 AM »
But the idea is that if I have a big screen, the text won't remain small in the button, but will increase in size so the proportion of button versus text is the same.
That is why I put the label on shrink content and the font size on 40-something, so the bigger the screen gets, the bigger the fontsize (since the label area grows bigger).
If I make the label area bigger with the font sized 40 and keep the same sized button then it will ofcourse grow out of proportion with the button.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Anchoring labels with same fontsize for different screen sizes
« Reply #6 on: July 31, 2014, 11:44:25 AM »
Why are you doing all this? Why don't you just change the UIRoot to Fixed Size? Then your UI will remain proportional to the height of the screen, meaning your font size will remain proportionally identical as well. You seem to be going about it backwards to me. Looking at the pics you can also benefit by adding 1 pixel transparent border around your letters.

eadwine

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Anchoring labels with same fontsize for different screen sizes
« Reply #7 on: August 01, 2014, 09:30:23 AM »
Thank you! Seems I was making it way too difficult for myself lol. Fixed size helped tons :)