Author Topic: UILabel width doesn't seem to update when you put text into it  (Read 14312 times)

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
UILabel width doesn't seem to update when you put text into it
« on: October 30, 2013, 03:59:10 AM »
Using 3.03, I have a UILabel with the text 'Message' in it, the width parameter is 106. But when in a Start function I change the text in the label, the width still says 106, but after 1 frame it goes to 305 (the actual width of the string)
What I need is the width to be updated and correct when I add a string to the label.

Any ideas what's wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel width doesn't seem to update when you put text into it
« Reply #1 on: October 30, 2013, 05:07:22 AM »
Bug, will be fixed in the next update.

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: UILabel width doesn't seem to update when you put text into it
« Reply #2 on: October 30, 2013, 07:46:36 AM »
Seems, that it is updating in text call or something. Working Temporaly solution is to call right after Text setting:
uilabel.ProcessText(false);

of course, ProcessText should be accessible.  :o
I'm a busy man... I have places to go,monsters to kill...

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: UILabel width doesn't seem to update when you put text into it
« Reply #3 on: October 30, 2013, 07:50:25 AM »
..Or even better - call process function in Text setter:

UILabel.cs:
  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)) mText = "";
  12.                                 hasChanged = true;
  13.                         }
  14.                         else if (mText != value)
  15.                         {
  16.                                 mText = value;
  17.                                 hasChanged = true;
  18.                                 ProcessAndRequest();
  19.                         }
  20.                         //Here is the solution!!
  21.                         if (hasChanged)ProcessText();
  22.                 }
  23.         }
I'm a busy man... I have places to go,monsters to kill...