Author Topic: Restrict Within Panel problem  (Read 6186 times)

Jason

  • Guest
Restrict Within Panel problem
« on: July 27, 2012, 10:54:50 AM »
hi,

I have run into a problem related to the "Restrict Within Panel" option for the scrolling mechanism.

Once a while I need to regenerate ScrollContent by script. If I attempt to drag the regenerated content in my vertical scroll, the content will be shifted to the left by about half a panel. This happens every time. If I disable the "Restrict Within Panel" option, my content will stay centered. Although I would like to have the "Restrict Within Panel" function enabled in my final release.

Any idea what's going on?

Jason

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Restrict Within Panel problem
« Reply #1 on: July 27, 2012, 03:02:01 PM »
Adjust your panel's clipping so that there is no extra space. It shifts because it always aligns to the top-left corner by default. Alternatively you can change "relativePositionOnReset" to be (0.5, 0.0), which would mean that it will start at the top edge.

Jason

  • Guest
Re: Restrict Within Panel problem
« Reply #2 on: July 28, 2012, 09:19:35 AM »
I'll give it a try. The thing is, it works fine before I regenerate my scrollPanel content. Also, each time I regenerate my scrollPanel content, it shifts further until it is totally off the screen.

I'll pay more attention to my content dimensions.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Restrict Within Panel problem
« Reply #3 on: July 28, 2012, 11:51:42 AM »
You need to reset the scroll view's position prior to changing its contents, or it may shift since the panel has moved.

Jason

  • Guest
Re: Restrict Within Panel problem
« Reply #4 on: July 28, 2012, 08:24:15 PM »
My bad. I found an unnecessary UIPanel within the clipped Panel, which caused other issues too. Any way, after removing it, NGUI works beautifully.

In case anyone else wants to regenerate the scroll panel content, here is how to restore the panel to where you left it off:
      // Restore the scroll position
      transform.parent.GetComponent<UIDraggablePanel>().SetDragAmount(0f, scrollValue,true);      
      // Restore the clipping range
      transform.parent.transform.GetComponent<UIPanel>().clipRange = clipRange;

Am I right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Restrict Within Panel problem
« Reply #5 on: July 28, 2012, 08:31:16 PM »
Sure, but that code doesn't check to see if the clip range is actually within range. As in, if you go from the end of a really long list to a short one, calling that code will show nothing, because the panel will be scrolled too far down. You might want to call UIDraggablePanel.RestrictWithinBounds(false).

Jason

  • Guest
Re: Restrict Within Panel problem
« Reply #6 on: July 29, 2012, 06:50:26 AM »
Great! Thanks mucho!