Author Topic: UIInput buggy with some alignments  (Read 1779 times)

mkoponen

  • Guest
UIInput buggy with some alignments
« on: January 13, 2013, 09:44:41 PM »
UIInput only works with left and top-left alignment in 2.2.7c . Things work fine until text gets longer than the field, in which case it jumps to an incorrect location if you use another alignment. Replacing this original code in UIInput.cs:

  1. if (fit != processed)
  2. {
  3.         processed = fit;
  4.         Vector3 pos = label.cachedTransform.localPosition;
  5.         pos.x = mPosition + label.lineWidth;
  6.         label.cachedTransform.localPosition = pos;
  7.        
  8.         if (mPivot == UIWidget.Pivot.Left) label.pivot = UIWidget.Pivot.Right;
  9.         else if (mPivot == UIWidget.Pivot.TopLeft) label.pivot = UIWidget.Pivot.TopRight;
  10.         else if (mPivot == UIWidget.Pivot.BottomLeft) label.pivot = UIWidget.Pivot.BottomLeft;
  11. }
  12.  

...with this (note the bug in the last line of the original code; should set to BottomRight):

  1. if (fit != processed)
  2. {
  3.         processed = fit;
  4.         Vector3 pos = label.cachedTransform.localPosition;
  5.  
  6.         if (mPivot == UIWidget.Pivot.Left || mPivot == UIWidget.Pivot.TopLeft || mPivot == UIWidget.Pivot.BottomLeft) {
  7.                 pos.x = mPosition + label.lineWidth;
  8.         } else if (mPivot == UIWidget.Pivot.TopRight || mPivot == UIWidget.Pivot.BottomRight || mPivot == UIWidget.Pivot.Right) {
  9.                 pos.x = mPosition - label.lineWidth;
  10.         }
  11.         label.cachedTransform.localPosition = pos;
  12.  
  13.         if (mPivot == UIWidget.Pivot.Left) label.pivot = UIWidget.Pivot.Right;
  14.         else if (mPivot == UIWidget.Pivot.TopLeft) label.pivot = UIWidget.Pivot.TopRight;
  15.         else if (mPivot == UIWidget.Pivot.BottomLeft) label.pivot = UIWidget.Pivot.BottomRight;
  16.         else if (mPivot == UIWidget.Pivot.Right) label.pivot = UIWidget.Pivot.Left;
  17.         else if (mPivot == UIWidget.Pivot.TopRight) label.pivot = UIWidget.Pivot.TopLeft;
  18.         else if (mPivot == UIWidget.Pivot.BottomRight) label.pivot = UIWidget.Pivot.BottomLeft;                                
  19. }
  20.  

...seems to do the trick. For the time being, I'll manage with my local fix, but obviously it would be nice to have this fixed in the next release.

(Right-align doesn't work out of the box, you have to fiddle a bit with the collider coordinates and so forth so that everything is in the same place. But at least with this code fix you can do it.)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput buggy with some alignments
« Reply #1 on: January 14, 2013, 12:06:31 AM »
Actually, the input field has always had a left-aligned requirement. It's not a bug per-say.

mkoponen

  • Guest
Re: UIInput buggy with some alignments
« Reply #2 on: January 14, 2013, 06:41:48 AM »
Well, at least this line is certainly a bug:

  1. else if (mPivot == UIWidget.Pivot.BottomLeft) label.pivot = UIWidget.Pivot.BottomLeft;

...as it tries to handle this particular alignment but does it wrong. And with my right align fix it works exactly as one might expect when it's handling too long input, so that it is surprising it wasn't intended.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput buggy with some alignments
« Reply #3 on: January 15, 2013, 07:12:57 AM »
You're right about that one. I'll fix it, thanks! :)