Author Topic: UIScrollView with UITable/UIGrid. Have to call Reset Position after first insert  (Read 7718 times)

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Hi guys
I'm noticing that for many of my cases, after my first insert in a UITable/UIGrid the entry gets put wherever(vertically) within the clipping panel.
Its only after I do a Reset Position on the scroll view(which shifts the scrollview y upwards) does it properly move to the top.
I'm trying to figure out if others have experienced this as well or if its just me due to my setup.
The way I have it set up is

Panel with soft clip|UIScrollView(The panel has anchors defined)
|
UITable/UIGrid

I usually make it look correct in the scene(by test adding an item under UITable/UIGrid then deleting it after all positioning is done).
I sometimes wondered if some anchoring on a parent was messing things up. But irrespective of that I believe when an item gets added it calls to reset position on the scrollview right?
Shouldn't that take care of things?

Thanks

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
looking at the forums alot of the subject are all about the scrollview not working as expected, I think the scrollview needs some Aren love.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You need to call Reposition() on the grid/table after adding content to it, and ResetPosition() on the scroll view after modifying the content within.

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Honestly I do believe that reposition on my table/grid is being called after adding my content(I'm using Ndata->ItemsSourceBinding). Perhaps the problem is that it gets called too early right after adding content. Perhaps it needs to be called after a certain amount of time.
I sort of solved it by doing a half second delayed reposition on the table/grid but it leads to an ugly shift of the contents. I think its very important for the positions to be correct before content is added otherwise its gonna lead to glitchy twitchy look and feel.

Also I was hoping that the call to scrollbar's UpdateScrollbar from UITable/UIGrid's Reposition would take care of positioning on the scrollview. Would it not? Please definitely let me know about this.(I will continue experimenting)

You know what, I'm gonna try repositioning it before adding any content to it. Hopefully it positions it properly such that when the first piece of content is added to the scrollview it comes up in the right place.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
It would, yes. However for any of this to work, the content must be already present in the scroll view's panel's list. If you instantiate content, it won't actually be added to the panel's list until later. If you want it to be right away, you need to Broadcast("CreatePanel") to the instantiated object.

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
I'm also noticing that the problems with vertical positioning only happen when there is content less than the size of the panel.

If there is more content than can fit within the panel's region, it seems to position just fine. Any thoughts why it behaves like this. Or is just that processing takes longer with more content(enough to allow the uitable/grid to position itself?)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I don't think it's anything related to processing time. When content doesn't fit, additional code may run that forces it to be repositioned. When the content fits, it may not. Depending on what you chose on the scroll view and such.

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Ok.
Also in reference to "It would, yes. However for any of this to work, the content must be already present in the scroll view's panel's list. If you instantiate content, it won't actually be added to the panel's list until later. If you want it to be right away, you need to Broadcast("CreatePanel") to the instantiated object."

How can I know when my instantiated content has been added to the panel's list?
Or as another option how do I do this Broadcast("CreatePanel")? You said broadcast to the instantiated object. Shouldn't it be the instantiated object broadcasting to the panel?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
  1. scrollView.gameObject.BroadcastMessage("CreatePanel");
Widgets aren't added to panels right away because at that point the parent hasn't been set yet.

1. Instantiate/AddChild immediately results in:
- UIWidget.Awake()
- UIWidget.OnEnable()
2. You (or AddChild) then set the parent.
3. UIWidget.Start() and UIWidget.Update() runs sometime later and adds to the panel draw lists.
4. UIPanel.LateUpdate() finally creates the draw calls.

There is no way to set the parent on object instantiation, so it's not possible to set it before Awake/Enable. It's a Unity limitation that I've had to work around.