Author Topic: Bug in UILable.  (Read 2886 times)

Romulus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Bug in UILable.
« on: March 21, 2014, 09:25:19 AM »
Behavior of UILable has changed when Overflow option is set to ResizeHeight. If the value of UILable contains a word with length exceeding Dimensions X, UILable ignores the rest of the text and doesn't show it (truncates).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug in UILable.
« Reply #1 on: March 21, 2014, 01:10:25 PM »
Seems fine here.

1. New scene.
2. ALT+SHIFT+L
3. Changed text to "Testing" and Overflow to ResizeHeight.
4. Resized the width so that only "Test" shows. Works fine.

makeshiftwings

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Bug in UILable.
« Reply #2 on: March 22, 2014, 06:32:24 PM »
I'm seeing the same bug as Romulus.  Not sure what's causing it yet.

makeshiftwings

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Bug in UILable.
« Reply #3 on: March 22, 2014, 07:04:47 PM »
I stepped through the code and see why it fails.  In NGUIText.cs, line 874:

  1. // Doesn't fit?
  2. if (Mathf.RoundToInt(remainingWidth) < 0)
  3. {
  4.         // Can't start a new line
  5.         if (lineIsEmpty || lineCount == maxLineCount)
  6.         {
  7.                 if (ch != ' ' && !eastern)
  8.                 {
  9.                         fits = false;
  10.                         break;
  11.                 }
  12.  
If it reaches the max length of the line, and the character is not a space, it immediately breaks out of the for loop and returns fits = false.  But the fits value is ignored by everything except ShrinkToFit.  So the string buffer only contains the text it got to at that point, which truncates everything else, and never actually wraps the text either.

makeshiftwings

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Bug in UILable.
« Reply #4 on: March 22, 2014, 07:24:34 PM »
FYI, I changed that "!eastern" to "eastern" and it works again.  Of course I'm not using Eastern fonts, so I don't really know if that somehow breaks something else if you are using Eastern fonts; I couldn't figure out what that section of code was really trying to do. :B

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug in UILable.
« Reply #5 on: March 23, 2014, 02:42:45 AM »
What's the text you're printing and how come am I not seeing any issues on my end with the steps I posted?

You can also try changing that code to:
  1.                                         // This is the first word on the line -- add it up to the character that fits
  2.                                         sb.Append(text.Substring(start, Mathf.Max(0, offset - start)));
  3.  
  4.                                         if (ch != ' ' && !eastern)
  5.                                         {
  6.                                                 fits = false;
  7.                                                 break;
  8.                                         }
...so that it exits after setting the text.

Romulus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Bug in UILable.
« Reply #6 on: March 24, 2014, 02:37:22 AM »
To see a bug you should make those steps

1) Create New Scene;
2) Add Label;
3) Change Font to "SciFi Font - Normal", size to 20;
4) Change text to "Testing Text" and Overflow to ResizeHeight;

5) Change Dimensions X = 100 (Bug: No);
6) Change Dimensions X = 60 (Bug: Yes).

Added screenshots:

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug in UILable.
« Reply #7 on: March 24, 2014, 04:03:06 PM »
Ok, I see -- thanks. Change the NGUIText.WrapText function, line 880 to just this:
  1.                                         // This is the first word on the line -- add it up to the character that fits
  2.                                         sb.Append(text.Substring(start, Mathf.Max(0, offset - start)));
  3.                                         if (ch != ' ' && !eastern) fits = false;