Author Topic: UIScrollView with UITable positioning problem. Please help!  (Read 8590 times)

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Hi guys
I have several UITables set up as children of their respective UIScrollViews. So UIScrollView and underneath it a UITable. However there is this single one which refuses to work properly.
The problem is that there is some space on top, like from the top ceiling of the scrollview's clipping panel and the top ceiling of the first row in the table.

All of them have very similar settings. I'm mentioning some of the pertinent settings. (This are the same for all of my UIScrollView/UITable combos)
1. The scrollview is of vertical kind and has content origin set to TopLeft in all the cases. I believe this will position the content properly based on clip panel's bounds right?(vertical will ignore x position). When I hit UIScrollView's "Reset clipping position" it positions the contents to top left of the UIScrollView's clipping panel perfectly, the way it should have been to begin with.
2. UIScrollView has Restrict within panel turned on.
3. UITable also has Keep within panel turned on. I have noticed that if I uncheck this, the table's position doesn't change automatically and its all messed up. But shouldn't ScrollView's restrict within panel in combination with Content origin have taken care of this?

Please help. Want to clear this once and for all.

Basically how should I go about designing ScrollViews with UITable in the editor to have the same results while running the game? My UITables and even the rows added from my prefabs are having their x changed. Need better understanding of how UIScrollViews work with UITables and what do I need to do so that the Top Left of the contents of UIScrollView are how I see them in the editor?
Thanks
« Last Edit: July 16, 2014, 08:00:58 PM by coolaneasy »

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: UIScrollView with UITable positioning problem. Please help!
« Reply #1 on: July 16, 2014, 07:59:53 PM »
Btw, it seems like when there is more content that the bounds of the clipping panel the positioning seems fine. It seems to occur when there is not enough content to fill up the uitable to make it grow outside the clip bounds.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView with UITable positioning problem. Please help!
« Reply #2 on: July 17, 2014, 02:48:27 AM »
As I recall keepWithinPanel option is what restricts the content so that it's within the panel's bounds. If you uncheck this, then table won't notify the panel when its dimensions change, and the panel won't adjust anything or re-evaluate its bounds. I used it in the Quest Log example to ensure that when I shrinik the content, the panel's scroll bar updates properly.

The content within the panel won't be moved if it fits within the panel, although calling UIScrollView's ResetPosition() function should force it. You mention Reset Clipping Position moves it correctly, and all it does is calls the ResetPosition() function. So have you tried calling it after populating your table's content?

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: UIScrollView with UITable positioning problem. Please help!
« Reply #3 on: July 17, 2014, 12:04:09 PM »
Yes I did try calling that function and that does position it correctly.
However 2 things
1. It causes this ugly twitchy shift of the contents and I didn't find it sophisticated.
2. I have several other UIScrollView/UITable combos and they are working fine. The contents show up at the top just fine. So I'm trying to figure out whyyyy in the world is this one acting like this.

1 difference I did notice is that in all the working examples, the red rectangle surrounding the table's contents is inside the clip panel. In the one thats causing positioning problems, the right hand side of the red rectangle is going outside the clip panel. But since mine is a vertical table I was expecting it to be ignored. Guess it still matters.

I'm trying to figure out what constitutes the dimensions of this red rectangle gizmo so that I can reduce it to be inside the clip panel but can't figure out so far. I looked into my table's first and only content and reduced all the child elements to become small and the red rectangle's size didn't change. I did this at run time though. Will now test in editor and see if reducing them there helps. Your thoughts??

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: UIScrollView with UITable positioning problem. Please help!
« Reply #4 on: July 17, 2014, 01:06:29 PM »
Okay so fixing the prefab of UITable's content reduced the size of red rectangle and that seems to have alleviated the problem. However I do have a question.

Even though my ScrollView is set to Content Origin of TopLeft it seems that the rows stick to the top right. I tested this by expanding the right side of clipping panel and my rows moved to the right. I had to narrow the clipping panel just right for the rows to be where I wanted them.
A row is made of
1. Main sprite. Non anchored. Top Left pivot
2. Secondary sprite. Anchored to Main sprite. Top left pivot.
3. Bunch of labels. All within the bounds of the sprites.

To me this behavior sounds wrong with the Content Origin set to TopLeft. I'm not sure who is doing the positioning of the table inside the clipping panel. Is it the UITable itself since it has the Keep within panel option on or is it the ScrollView? I wish there was 1 authoritative way this worked.

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: UIScrollView with UITable positioning problem. Please help!
« Reply #5 on: July 17, 2014, 04:14:15 PM »
Btw, I looked at the Quest log example to clear my confusion of how the table's bounds(indicated by the red rectangle) are figured out. Seems like its based on the contents of the table itself but only if its static time. Dynamic content seems to create problems with this bounds calculation.
ps I do have dynamically visible sprites in my row too. Just wanted to throw it up here in case I was doing something differently/incorrectly.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView with UITable positioning problem. Please help!
« Reply #6 on: July 18, 2014, 05:09:10 AM »
The best way to go is to have a container widget that you'd anchor things to that would also envelop all your content.

Widget (ALT+SHIFT+W)
- Main sprite, within the bounds of the widget, anchored
- Secondary sprite, within the bounds of the widget, anchored
- Labels, within the bounds of the widget.

Any reason why you're doing this dynamically and not creating a prefab out of your row and instantiating that instead? Note that anchors get updated in Update(), so your anchored sprite may simply not be positioned at the time you need it to. You can force it to be positioned by calling UpdateAnchors(), or NGUITools.ImmediatelyCreateDrawCalls.

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: UIScrollView with UITable positioning problem. Please help!
« Reply #7 on: July 22, 2014, 02:30:25 PM »
Okay I'll start doing it like having widget as parent.
I had 1 situation where the top parent was a gameobject and it had 2 optional(only 1 active at at a time) and UITable seemed to be treating the 2 children as independent children of its contents. This was until I put a UIWidget on the parent gameobject.

When I said created dynamically, I just meant instantiated dynamically from a prefab. Sorry for the confusion.