Author Topic: UIGrid pivot does nothing. Always renders on TopRight.  (Read 8778 times)

pdelaossa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
UIGrid pivot does nothing. Always renders on TopRight.
« on: November 11, 2014, 06:16:20 AM »
Hi ArenMook.

I created an UIGrid, which I'm going to populate dynamically using NGUITools.AddChild.

When I simply populate and then show it, it doesn't have enough time to properly reposition the children.
<image attachment number 1>
They are shown all over the place.

That's why I created a coroutine to wait for exactly 2 frames before calling Reposition and then showing it.

But then, for some reason, it always positions them on TopRight pivot, whatever pivot I pick, and however much I wait or reposition.
<image attachment number 2>

Any ideas?

cuidaguang

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 5
    • View Profile
Re: UIGrid pivot does nothing. Always renders on TopRight.
« Reply #1 on: November 12, 2014, 05:03:18 AM »
I guess the pivot works fine.
You can try add 3 elements to the UIGrid and see.
If you want to move the place of the UIGrid, don't attach UIGrid Script and UIPanel to the same GameObject.
Attach UIGrid to a child of the gameobject that the UIPanel attached to, and adjust the transform.

pdelaossa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UIGrid pivot does nothing. Always renders on TopRight.
« Reply #2 on: November 12, 2014, 11:16:54 AM »
I guess the pivot works fine.
You can try add 3 elements to the UIGrid and see.
If you want to move the place of the UIGrid, don't attach UIGrid Script and UIPanel to the same GameObject.
Attach UIGrid to a child of the gameobject that the UIPanel attached to, and adjust the transform.

Something is not working right and I guessed it was the pivot, because it is on TopLeft and it is placing them incorrectly as seen in the picture. It seems to be placing them in TopRight.

Whatever I do. It doesn't matter if I add 3 more elements, dynamically in runtime or manually on the editor.

I don't want to move the UIGrid using transform. It is properly anchored in the exact position I want it. You can see the square that is the UIPanel and it is placed correctly. And adding the UIGrid component to a child of the UIPanel, and then anchoring that one on the right place behaves in the exact same way.

I'm attaching a third picture that shows how it behaves as you asked, with 3 more items.
« Last Edit: November 12, 2014, 11:22:11 AM by pdelaossa »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid pivot does nothing. Always renders on TopRight.
« Reply #3 on: November 14, 2014, 04:29:36 AM »
Grid's pivot point simply changes the grid's position after all items get placed. If you want them to grow toward the left instead of right, change the cell X size to a negative number.

pdelaossa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UIGrid pivot does nothing. Always renders on TopRight.
« Reply #4 on: November 14, 2014, 05:42:09 AM »
Grid's pivot point simply changes the grid's position after all items get placed. If you want them to grow toward the left instead of right, change the cell X size to a negative number.

What I want is for the first item to render on the Top Left corner of the panel.

This is, that the UIGrid anchors to the top left. I don't want it floating aimlessly on the right corner as you can see in all the pictures. I want to give support to all kind of aspect ratios, thus anchoring and not absolute position (with transform).

Sorry for not pointing this out explicitly/accurately.
« Last Edit: November 14, 2014, 10:44:46 AM by pdelaossa »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid pivot does nothing. Always renders on TopRight.
« Reply #5 on: November 15, 2014, 04:12:04 PM »
The grid simply changes the position of transforms below it. It isn't even working with widgets -- it works with transforms. Meaning whatever the pivot point of the content below the grid, that will be the position that will be adjusted. As such, if your content's pivot points are top-right, then it will indeed extend below and to the left. If the content's pivot is bottom-left, it will extend upwards and to the right.

Don't forget to call the UIScrollView's ResetPosition() after resetting your grid.

pdelaossa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UIGrid pivot does nothing. Always renders on TopRight.
« Reply #6 on: December 01, 2014, 06:43:09 AM »
The grid simply changes the position of transforms below it. It isn't even working with widgets -- it works with transforms. Meaning whatever the pivot point of the content below the grid, that will be the position that will be adjusted.

Then, the problem persists. How am I supposed to give support to different aspect ratios if the UIGrid object is positioned using absolute values in transform?

As an example, for a 4:3 aspect ratio its x-axis position must be x= -400px, and for 16:9 x= -632px.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid pivot does nothing. Always renders on TopRight.
« Reply #7 on: December 02, 2014, 11:34:45 AM »
By not using UIGrid. UIGrid works with absolute values, as you pointed out. Write a simple script to position your content instead by deriving from UIGrid and overwriting its Reposition() function. Or easier yet, make "ResetPosition" function virtual, and overwrite that instead. You can then position your content exactly as you like.