Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: arkon3 on October 30, 2013, 03:59:10 AM

Title: UILabel width doesn't seem to update when you put text into it
Post by: arkon3 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?
Title: Re: UILabel width doesn't seem to update when you put text into it
Post by: ArenMook on October 30, 2013, 05:07:22 AM
Bug, will be fixed in the next update.
Title: Re: UILabel width doesn't seem to update when you put text into it
Post by: AGB 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
Title: Re: UILabel width doesn't seem to update when you put text into it
Post by: AGB 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.         }