Author Topic: [3.4.9] ResizeFreely labels sometimes wrapping the last character  (Read 4739 times)

vallcrist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 49
    • View Profile
sometimes ( usually when there's a resolution change ) the last characters of a label gets wrapped down.

Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #1 on: February 11, 2014, 07:45:13 PM »
Can you let me know if there a consistent way for me to reproduce it?

vallcrist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 49
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #2 on: February 11, 2014, 09:18:03 PM »
Ok. I find this happening often when the game windows changes resolution abruptely, like fullscreen or some resizes made by the Facebook SDK.

If i manage to reproduce it consistently, i'll let you know, but it does seem very random.

Also, this seems to have appeared after i moved from 3.0.9 f1 to 3.0.9 f4 and later.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #3 on: February 12, 2014, 03:44:47 AM »
Same problem here, but when you press on the play button in the editor it resets itself. I'm using xARM plugin for checking screen sizes and it happens a lot when the resolution of the screen changes.

vallcrist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 49
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #4 on: February 20, 2014, 08:47:49 PM »
Ok, found a way to reproduce it consistently on my machine.

New scene.

Add a Label, Dynamic Font, Arial Size 25, resize freely

Write "Item Title", and then change the horizontal pivots, last character will break.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #5 on: February 21, 2014, 04:56:15 PM »
Did you try it in 3.5.0? I can't repro it...

vallcrist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 49
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #6 on: February 23, 2014, 01:25:39 AM »
Yup, still happens in 3.5.1

vallcrist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 49
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #7 on: February 23, 2014, 01:28:44 AM »
Oh i also forgot something, UIRoot is Fixed Size, 720px height

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #8 on: February 23, 2014, 12:27:57 PM »
1. New scene.
2. ALT+SHIFT+L, chose Arial, size 25, Resize Freely, typed "Item Title" for text.
3. UIRoot changed to fixed size, 720.
4. Changed pivots around -- left, center, right, top, bottom, bottom left, etc... nothing. Everything works fine.

timt

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #9 on: February 26, 2014, 09:43:40 PM »
I think I have the same or very similar issue and I'm on the latest code. Try these steps :

1. New scene.
2. ALT+SHIFT+L, chose Arial, size 25, Resize Freely, typed "MISSIONS" for text. Choose Keep Crisp - Always.
3. UIRoot changed to fixed size, 1200.
4. Add a TweenColor to the label. Set the target color to something. Set the start delay to 5 seconds.
5. Shrink your editor window to as small as you can vertically. This works best if the layout has the game view by itself vertically so you can make it very short.
6. Run. Then quickly enlarge the editor window to as tall as you can make it.
7. When the tween color goes off the label should wrap the last character.

As far as I can tell, the problem is that when mWidth is determined in ProcessText, this is based on the starting pixel density, but when it's drawn in NGUIText.Print it's using whatever the current pixel density is, and that can cause wrapping to occur. My simple fix is to save the pixel density used to calculate CalculatePrintedSize in ProcessText and in UILabel.OnFill, check it see if the pixel density has changed and if it has, call ProcessText before doing the draw. Does that seem like a reasonable fix?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #10 on: February 27, 2014, 05:50:28 PM »
That seems reasonable to me. So to clarify, you did this?

1. Added "float mDensity' to UILabel.
2. Set mDensity before calling UpdateNGUIText in UILabel.ProcessText:
  1.                 bool isDynamic = (trueTypeFont != null);
  2.  
  3. #if DYNAMIC_FONT
  4.                 if (isDynamic && keepCrisp)
  5.                 {
  6.                         UIRoot rt = root;
  7.                         if (rt != null) mDensity = (rt != null) ? rt.pixelSizeAdjustment : 1f;
  8.                 }
  9.                 else mDensity = 1f;
  10. #endif
  11.                 UpdateNGUIText(mPrintedSize, mWidth, mHeight);
3. In UILabel.UpdateNGUIText, added a check after the pixel density calculation:
  1.                 if (isDynamic && keepCrisp)
  2.                 {
  3.                         UIRoot rt = root;
  4.                         if (rt != null) NGUIText.pixelDensity = (rt != null) ? rt.pixelSizeAdjustment : 1f;
  5.                 }
  6.                 else NGUIText.pixelDensity = 1f;
  7.  
  8.                 if (mDensity != NGUIText.pixelDensity)
  9.                 {
  10.                         ProcessText(false);
  11.                         NGUIText.rectWidth = mWidth;
  12.                         NGUIText.rectHeight = mHeight;
  13.                 }
Is that right?
« Last Edit: February 28, 2014, 05:40:18 PM by ArenMook »

timt

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #11 on: February 28, 2014, 03:27:35 PM »
Almost the same. I was doing the density check and call to ProcessText at the top of OnFill. Your solution is better.

timt

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #12 on: February 28, 2014, 05:08:37 PM »
Actually, now that I think about it, your code won't work. The problem being that width and height being passed into UpdateNGUIText is generally mWidth and mHeight and wouldn't be updated until the ProcessText call and therefore rectWidth and rectHeight would be incorrect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [3.4.9] ResizeFreely labels sometimes wrapping the last character
« Reply #13 on: February 28, 2014, 05:40:38 PM »
Good point. I've updated the code so that it sets the rect width and height.