Author Topic: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)  (Read 9791 times)

artfabrique

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 45
    • View Profile
Hi!
I've found 2 very annoying bugs. NGUI 3.7.5

1) UILabel with ResizeFreely wraps/drops last character to a new line.
2) It takes up to 10 frames to for native NGUI anchoring system to reposition UILabel (ResizeFreely, align left) with advanced anchoring (top,left) to another UILabel (ResizeFreely, align center).

This bugs do not allow to calculate bounds of multiple widgets so we could wrap them with background sprite + this flickering is visually unattractive.

Here is a video-demo:
https://www.dropbox.com/s/m2ma4k5cdbmz62y/NGUIAnchorUILabel.wmv?dl=0

Here is sources (without NGUI & UnityVS)
https://dl.dropbox.com/s/61l0oukpuwxq1o7/NGUIAnchorsUILabel_Pack.zip
« Last Edit: November 20, 2014, 02:19:50 PM by artfabrique »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #1 on: November 20, 2014, 09:15:18 PM »
I'll have a look at this tomorrow, but for now it would be really helpful to know the steps to reproduce the issue in a project with just NGUI present rather than a whole project to look at.

artfabrique

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #2 on: November 21, 2014, 10:44:34 AM »
I'll have a look at this tomorrow, but for now it would be really helpful to know the steps to reproduce the issue in a project with just NGUI present rather than a whole project to look at.
I've zipped just a test project sources without any other extensions. Very clean and tidy. But i've excluded NGUI package of course as you've asked (we use licensed version)
Steps:
1) Create Bitmap Font 1 with NGUI FontMaker size 20
2) Create Bitmap Font 2 with NGUI FontMaker size 24
3) Create UILabel1
4) Create UILabel2
5) Set UILabel 2 font, font size - 20, effect outline with black and 175 alpha, align left, pivot center-center
6) Set UILabel 1 font, font size - 24, effect outline with black and 175 alpha, spacing x -1, align center, pivot center-center
7) Set UILabel 2 anchors to Advanced
8 ) Drop UILabel 1 to top and left anchor fields.
9) Move UILabel 2 a little bit with keyboard arrows and mouse. (strange anchors behaviour could be seen even here - numbers not always get updated)
10) Now just set random text to both text fields at runtime

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #3 on: November 22, 2014, 01:22:56 PM »
I followed your instructions with your scene, and everything works as expected. The only thing I changed is I pixel-perfected your 2nd label. It had a position of 115.5 or something like that. It should have used integer values (ie: 115).

Clicking the randomize button changes the text, making the labels adjust right away. The 2nd label's right and bottom sides are left not anchored, meaning they stay exactly where they were.

Looking at your video I spotted the difference however. You set the 2nd label to also Resize Freely, which is not how it is in your example, and you didn't mention it in the steps either.

The problem occurs because of a combination of centered pivot and anchoring. Change the pivot to top-left, and the problem goes away. Reason for it is simple: when you enter text in a label, its dimensions can become uneven: ie: non-dividable by two. Centered pivot requires dimensions to be dividable by two, otherwise you get floating point values.

artfabrique

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #4 on: November 24, 2014, 05:25:51 AM »
The problem occurs because of a combination of centered pivot and anchoring. Change the pivot to top-left, and the problem goes away. Reason for it is simple: when you enter text in a label, its dimensions can become uneven: ie: non-dividable by two. Centered pivot requires dimensions to be dividable by two, otherwise you get floating point values.
But what if i want a center alignment in a text field? If i switch center-pivot of the white bold uilabel to the top-left i loose center text aligment.
I think the solution is to ceil widths, heights and coordinanates of UILabel on each text change and anchor recalculation.

artfabrique

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #5 on: November 24, 2014, 01:13:01 PM »
I followed your instructions with your scene, and everything works as expected. The only thing I changed is I pixel-perfected your 2nd label. It had a position of 115.5 or something like that. It should have used integer values (ie: 115).

Clicking the randomize button changes the text, making the labels adjust right away. The 2nd label's right and bottom sides are left not anchored, meaning they stay exactly where they were.

Looking at your video I spotted the difference however. You set the 2nd label to also Resize Freely, which is not how it is in your example, and you didn't mention it in the steps either.

The problem occurs because of a combination of centered pivot and anchoring. Change the pivot to top-left, and the problem goes away. Reason for it is simple: when you enter text in a label, its dimensions can become uneven: ie: non-dividable by two. Centered pivot requires dimensions to be dividable by two, otherwise you get floating point values.

I've found another strange behaviour: the UILabel (pivot: top-left, text align: left, ResizeFreely, anchor: advanced-left-top to another UILabel with ResizeFreely) width will be wrong after i set a new text even if a call ProcessText() & ResetAndUpdateAnchors();
The right corners(top & bottom) will stay on prev positions while left corners will update and width will be incorrect.

Here is an example little bit tuned sources:
https://dl.dropbox.com/s/a3xr30fd9ht518j/NGUIAnchorsUILabel_Pack2.rar?dl=0

artfabrique

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #6 on: November 24, 2014, 01:51:05 PM »
I've found another strange behaviour: the UILabel (pivot: top-left, text align: left, ResizeFreely, anchor: advanced-left-top to another UILabel with ResizeFreely) width will be wrong after i set a new text even if a call ProcessText() & ResetAndUpdateAnchors();
The right corners(top & bottom) will stay on prev positions while left corners will update and width will be incorrect.

Here is an example little bit tuned sources:
https://dl.dropbox.com/s/a3xr30fd9ht518j/NGUIAnchorsUILabel_Pack2.rar?dl=0

Found out if set MarkAsChanged(); tan CalculateBounds returns right size but width still remains wrong

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #7 on: November 25, 2014, 01:32:14 AM »
But what if i want a center alignment in a text field? If i switch center-pivot of the white bold uilabel to the top-left i loose center text aligment.
...you can specify the Alignment on the label explicitly. It's a settable field in inspector.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #8 on: November 25, 2014, 01:35:00 AM »
Calling MarkAsChanged() followed by ProcessText() should be enough to update the width -- however this assumes that you perform this action after the anchor updates -- so call UpdateAnchors() first.

artfabrique

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: 2 Bugs! Two UILabels + Advanced Anchors + ResizeFreely (with demo)
« Reply #9 on: November 25, 2014, 04:25:58 AM »
...you can specify the Alignment on the label explicitly. It's a settable field in inspector.
Forgot to mention by "align - center" i mean UILabel with resize freely should resize to the both sides when text changes. But if you move pivot to the top left the center-aligned text will resize only to the right side. So text alignment will be visible only for multiline textfields i guess