Author Topic: Offset widget  (Read 13825 times)

dominus85

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 31
    • View Profile
Offset widget
« on: February 21, 2014, 07:43:53 AM »
Until now, if I had a width W widget, i used to offset from rights target for left and right:
for left: OFFSET
for right: OFFSET + W

I think this is not an elegant way of dealing with offseting widgets and I would be grateful for a better solution. I simply want the right edge of my widget to be at an OFFSET distance of a target, even if the widget width changes. Is there a simple way to do this without calculating the left and right offsets based on the widget width?

Since upgrading to 3.5.0b I am not sure the way I use still works

If I change the width of the widget used as Unified Anchor(let's call it reference), to widgets that are anchored to it will no longer change their position. They simply stay in the same place and the Left and Right constraints change accordingly. However, if I change the widget dimensions from editor, it works :)

I think the change that broke the functionality is this: https://github.com/tasharen/ngui/commit/1618d32c3e63d00146746df77f8f8d0bead40b09#diff-89a3fb27e36824b406e234bfeb9dcda3

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offset widget
« Reply #1 on: February 21, 2014, 02:27:54 PM »
If you want something to be anchored to the right, with a resizable width, anchor both left and right side of the widget, but change the pivot to top-right, right, or bottom-right.

You will be able to resize its width and since the pivot is on the right, it will adjust its position by expanding toward the left.

dominus85

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 31
    • View Profile
Re: Offset widget
« Reply #2 on: February 22, 2014, 11:28:39 AM »
Makes sense, your suggestion.. Will try

Now, regarding the bug I am describing above, here is the repro case https://www.dropbox.com/s/nzay2tvxvspiszo/tween_constraints.zip

the X sprite is anchored to the left of the button sprite..
i change the width of the button sprite with a tween width
if a tween is playing in the same time on X, X will not update its position based on the anchor constraints, but instead changes the constraints
if no tween is playing on X, the behaviour is as expected, with X moving along with the button

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offset widget
« Reply #3 on: February 23, 2014, 10:32:18 AM »
Tweens adjust the anchors, this is intentional.

dominus85

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 31
    • View Profile
Re: Offset widget
« Reply #4 on: February 24, 2014, 06:25:19 AM »
I think this should be a toggle, so I can choose the default behaviour.. I do not always want this behaviour to happen

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offset widget
« Reply #5 on: February 24, 2014, 04:33:36 PM »
If this doesn't happen, then nothing will happen when you tween, because the anchor will overwrite the tween's logic.

dominus85

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 31
    • View Profile
Re: Offset widget
« Reply #6 on: February 26, 2014, 03:59:30 AM »
Ok.. for anyone else having the same issue, the workaround is to create an empty GameObject as parent of the second Tweened element.