Author Topic: Bug: UILabel line wrapping adding an extra space for formatting symbols  (Read 41745 times)

MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
When a UILabel automatically wraps and a line ends with [/i] or similar, an extra space is rendered at the start of the new line. This was introduced sometime since NGUI 3.9. Screenshot is attached, thanks!

NGUI 3.11.2, Unity 5.5.2f1.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You actually have a space between "[/i]" and "New", and that's exactly what's being rendered. If you change the text to this, the issue disappears:
  1. New [i]Label [/i]New Line

MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
Hi Aren, thanks for the response! Soft-wrapped text should discard spaces at the new line, and this works properly in other cases in NGUI. The bug here is if the closing [/i] is where it decides to insert the new line character. My text does not have a hard new line character; if it did, I would agree it should render the space, but it does not.

Here is another screenshot showing NGUI doing the right thing in other cases, but the wrong thing in this case. Making the space italicized is perhaps a workaround, but you can't always control what text your label is showing. This was working correctly before and is a new bug.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Looked into this -- you can add this above line 1403 in NGUIText.cs:
  1. else
  2. {
  3.         // Skip spaces at the beginning of the line
  4.         while (start < offset && IsSpace(text[start])) ++start; // <--- this
  5.  
  6.         // Revert the position to the beginning of the word and reset the line
  7.         lineIsEmpty = true;
  8.         x = 0f;
  9.         offset = start - 1;
  10.         prev = 0;

MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
I added that line in, to no effect. It never enters the loop from what I can see.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Seems to work fine here... Perhaps revisit this after I put up the NGUI update?

MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
Sure thing, I'll watch out for that!

MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
Hi Aren, the same problem exists with NGUI 3.11.3.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
In that case I'll need to see what you're doing different, because I just made a label and this is what I see:

MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
Looks like the bug is fixed if Overflow is set to Clamp Content - but it's still there with Shrink Content (which I am using).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug: UILabel line wrapping adding an extra space for formatting symbols
« Reply #10 on: April 28, 2017, 10:08:59 AM »
It's the same thing.

MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
Re: Bug: UILabel line wrapping adding an extra space for formatting symbols
« Reply #11 on: April 28, 2017, 10:11:27 AM »
Ok, here is my test scene exhibiting the problem. Let me know if you have trouble opening it and I could email the whole project instead.


MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
Re: Bug: UILabel line wrapping adding an extra space for formatting symbols
« Reply #12 on: April 28, 2017, 10:17:11 AM »
Hmm perhaps the bug happens only when Shrink Content actually shrinks the text. If I play around with the font size I can see that happening.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug: UILabel line wrapping adding an extra space for formatting symbols
« Reply #13 on: April 28, 2017, 10:26:36 AM »
Are you sure you actually updated NGUI to the latest version? Here's your scene in my project. As-is, the size 20 font was drawn as size 16. I had to adjust the label's size a tad to make it match your size 18 from your pic above. Either way, looks fine:

MigrantP

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 22
    • View Profile
Re: Bug: UILabel line wrapping adding an extra space for formatting symbols
« Reply #14 on: April 28, 2017, 10:38:30 AM »
Yes, it's NGUI 3.11.3. I'm on Unity 5.6.0p1.

I can create a new Unity project with NGUI 3.11.3, import the scene I posted, and the problem is right there without making any changes.

Adjusting the size of the label actually lets you see the boundary where the bug is happening - at width 192-202 it happens, outside of that range it doesn't.

I'll send you a zip of the complete project.