Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: magnatua on February 12, 2013, 08:53:19 AM

Title: UILabel and lineWidth
Post by: magnatua on February 12, 2013, 08:53:19 AM
Hi!

I have some problem with UILabel.
If I want to change width of line UILablel like this:
  1. child.transform.FindChild("Tween").transform.FindChild("Description").GetComponent<UILabel>().lineWidth = 640;
  2. Debug.LogWarning("LineWidth = "+ child.transform.FindChild("Tween").transform.FindChild("Description").GetComponent<UILabel>().lineWidth);
  3.  

  1. LineWidth =  640

But a width did not change on an interface:(
I'm commented two line in UILabel.cs.
UILabel.cs
  1. protected override void OnStart ()
  2. {
  3.         if (mLineWidth > 0f)
  4.         {
  5. //      mMaxLineWidth = Mathf.RoundToInt(mLineWidth);
  6. //     mLineWidth = 0f;
  7.         }
  8.  
  9.         if (!mMultiline)
  10.         {
  11.                 mMaxLineCount = 1;
  12.                 mMultiline = true;
  13.         }
  14.  
  15.         // Whether this is a premultiplied alpha shader
  16.         mPremultiply = (font != null && font.material != null && font.material.shader.name.Contains("Premultiplied"));
  17. }

And all works well!!!!. What can a problem be in?
Title: Re: UILabel and lineWidth
Post by: magnatua on February 12, 2013, 10:02:37 AM
ArenMook, thanks for a quick answer!
Quote
You should be changing "max line width", not line width.

I can't find "max line width" ;(

(http://s48.radikal.ru/i121/1302/26/8456638abbcc.png)
Title: Re: UILabel and lineWidth
Post by: ArenMook on February 12, 2013, 10:10:11 AM
Actually I was wrong. Max line width is a member variable, which is set via the lineWidth property. There used to be a "mLineWidth" field, but it has been deprecated a while ago, serving only backwards functionality.

I am not sure why commenting those two lines makes it work for you, considering that the fields are not supposed to be used anymore. Did you create your UI with an old version of NGUI (like free version?) -- You need to resave with the latest full version.
Title: Re: UILabel and lineWidth
Post by: magnatua on February 12, 2013, 10:21:51 AM
Quote
Did you create your UI with an old version of NGUI (like free version?) -- You need to resave with the latest full version.

I have a full version and i use latest version 2.3.1.
Title: Re: UILabel and lineWidth
Post by: ArenMook on February 12, 2013, 10:25:41 AM
If that's the case, then this should never be triggered:
  1. if (mLineWidth > 0f)
...because mLineWidth is never changed from its initial 0 value.
Title: Re: UILabel and lineWidth
Post by: magnatua on February 12, 2013, 10:30:39 AM
Quote
If that's the case, then this should never be triggered:
Code: [Select]
if (mLineWidth > 0f)
...because mLineWidth is never changed from its initial 0 value.

And how i can then change the value at runtime?
Title: Re: UILabel and lineWidth
Post by: ArenMook on February 12, 2013, 10:31:22 AM
Exactly as you're doing it, by modifying the lineWidth property, which modifies "mMaxLineWidth" underneath.