Author Topic: UILabel and lineWidth  (Read 3925 times)

magnatua

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
UILabel and lineWidth
« 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?

magnatua

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UILabel and lineWidth
« Reply #1 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" ;(


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel and lineWidth
« Reply #2 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.

magnatua

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UILabel and lineWidth
« Reply #3 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel and lineWidth
« Reply #4 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.

magnatua

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UILabel and lineWidth
« Reply #5 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel and lineWidth
« Reply #6 on: February 12, 2013, 10:31:22 AM »
Exactly as you're doing it, by modifying the lineWidth property, which modifies "mMaxLineWidth" underneath.