Author Topic: Why Does NGUIText Break a Word When Wrapping?  (Read 3938 times)

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Why Does NGUIText Break a Word When Wrapping?
« on: February 10, 2014, 05:11:51 PM »
I've always wondered why when the text is wrapping, that you would ever want the word to be broken apart?
I usually go in and modify the code so it doesn't wrap if the character is not a space.

But why isn't that native behavior?

i.e.
"Wrapping Lines" is done like this:
"Wrappi
ng Lines"

Instead of:
"Wrapping
Lines"

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #1 on: February 10, 2014, 05:20:37 PM »
NGUI only breaks up a word like that if there is a single very long word on the line, and it doesn't fit. If you have spaces in between of words, it will always go by that first.

If you are seeing something different in the latest version, then I would need to know steps to reproduce the issue.

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #2 on: February 11, 2014, 06:51:50 PM »
NGUI only breaks up a word like that if there is a single very long word on the line, and it doesn't fit. If you have spaces in between of words, it will always go by that first.

If you are seeing something different in the latest version, then I would need to know steps to reproduce the issue.

Well, I've had this issue for quite a while. If there is any extra height on the box, it will wrap and chop up words. While the generic solution would be to "not have extra height allowing wrapping," sometimes during runtime, the string being placed in will be one longer word, sometimes it will be two words.

So in the case of a longer word that is just barely too long (like 1-2 characters) it get's chopped, not shrunk like I'd like.


  1.   // Doesn't fit?
  2.   if (remainingWidth < 0f)
  3.   {
  4.     // Can't start a new line
  5.     if (lineIsEmpty || lineCount == maxLineCount)
  6.     {
  7.       // This is the first word on the line -- add it up to the character that fits
  8.       sb.Append(text.Substring(start, Mathf.Max(0, offset - start)));
  9.  
  10.       if (lineCount++ == maxLineCount)
  11.       {
  12.         start = offset;
  13.         break;
  14.       }
  15.  
  16.       //============================ START MODIFICATION =================================
  17.       if (ch == ' ')
  18.           {
  19.             if (keepCharCount) ReplaceSpaceWithNewline(ref sb);
  20.             else EndLine(ref sb);
  21.             lineIsEmpty = true;                                                
  22.             start = offset + 1;
  23.             remainingWidth = rectWidth;
  24.           }
  25.           else
  26.           {
  27.             if (start < offset) sb.Append(text.Substring(start, offset - start));
  28.             finalText = sb.ToString();
  29.             return false;
  30.           }
  31.           //============================ END MODIFICATION =================================
  32.           prev = 0;
  33.         }
  34.        
  35.            ........................................
  36.            ......... skipping over ...........
  37.            ........................................
  38.        
  39.  
  40.     if (start < offset) sb.Append(text.Substring(start, offset - start));
  41.     finalText = sb.ToString();
  42.     //============================ START MODIFICATION =================================
  43.     if (remainingWidth < 0) return false;
  44.     //============================ END MODIFICATION =================================
  45.     return (offset == textLength) || (lineCount <= Mathf.Min(maxLines, maxLineCount));
  46. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #3 on: February 11, 2014, 07:36:26 PM »
Extra height? I'm not entirely sure what you mean. A pic or two might help me understand. NGUI wraps the word onto the next line if it's possible to make a new line. If it's not, then the word is cut up.

sunspider

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #4 on: April 03, 2014, 03:53:17 PM »
Not starting a new thread because this is so related to what I'm looking at...

My label _doesn't_ break a word when it's longer than the width of the text box. It's set to resize height, automatic alignment, and it's the display for a UIInput.

Thought I'd check in before trying to hack into the Textwrap code.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #5 on: April 03, 2014, 08:40:00 PM »
The functionality was changed since February which is when this thread is from.

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #6 on: April 10, 2014, 05:17:19 AM »
Can you give me some lines of code to get back the old behaviour (this is very important for our project) or make this feature optional?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #7 on: April 10, 2014, 07:31:10 AM »
Search NGUIText.cs for "eastern". Force it to be 'true' and you will have the old functionality back.

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #8 on: April 11, 2014, 02:43:36 AM »
Not completely since it doesn't even try to wrap complete words.

Quote
Derpy derped ar
ound his derpy d
erped house.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why Does NGUIText Break a Word When Wrapping?
« Reply #9 on: April 11, 2014, 07:25:37 AM »
Looking at the code you will also need to check to see if the line is empty or not, and if there is a space present or not. I can't give you specific code here because there have been quite a few changes to that file over the last few weeks. It's situations like these that having Pro level access is really helpful as it gives you access to the entire history of changes.