Author Topic: How to get Top of elements ScrollView from another panel  (Read 3750 times)

heisenburger

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
How to get Top of elements ScrollView from another panel
« on: February 19, 2014, 09:02:54 PM »
I'm sure the answer is simple but I have tried comparing the bounds from the ScrollView and the bounds of the element in the different panel (a header I want the scrolled items to scroll under) in order to find out when all of the elements in the scroll view are all lower y on the screen than the header (so I can implement something like a "quick return" header http://stackoverflow.com/questions/17516846/how-to-replicate-header-behavior-of-google-chrome-android-app and know when all of the elements are all below the header so it doesn't need to be "pushed" off the top of the screen).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to get Top of elements ScrollView from another panel
« Reply #1 on: February 20, 2014, 10:21:35 AM »
Sorry, I've re-read the post 4 times and I am still not certain what it is you're trying to do. I am not sure what "quick return" is. Do you mean return to the top when you go below a certain threshold? If so, just use SpringPanel.Begin to move to a specific location. UICenterOnClick uses it if you need an example.

heisenburger

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: How to get Top of elements ScrollView from another panel
« Reply #2 on: February 20, 2014, 11:29:58 PM »
Thanks for giving it a look!! here's some more information about what I'm trying to do (my question, rephrased, at the bottom).  Thank you very much for your time and the great support!



A. UIScrollView in it's "default" state.  Big white rectangle in the background is the screen size. The Grey bar at top os the "Quick Return Header." White numbered Bars are UIWidgets in a table that are visible.  Black Numbered bars are UIWidgets in a table that are not visible (disabled).

B) Big arrow on the left is the directon that the UIScrollView is moving in.  Quick Return Header moves off of the top of the screen with the list.  It will stay roughly where it is moved off, near the top of the screen, as we will see in C.

C) Conceptually, the UIScrollView list moves "past" the quick return header.  This is so that if you start to scroll down again, the Quick Return Header will reappear before you scroll all the way back to the top of the list as shown in D.

D) The list is scrolled down and the Quick return header scrolls down with it (after a certain amount of "play" in the UIScrollView moving down.

E) When the top of the elements in the UIScrollView Table moves down and past the Quick Return Header, it should stick at the top while the elements move down.  They should "spring" back to A after the "drag" represented by the arrow on the left ends.

My question is how to recognize when the E situation has obtained so that I can keep the Quick Return header from moving back up with the UIScrollView table if the user drags it back "up" while it is completely "under" the Quick Return Header

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to get Top of elements ScrollView from another panel
« Reply #3 on: February 21, 2014, 03:16:05 PM »
You wouldn't make your quick return header a part of the scroll view. It needs to be separate, or at best it will be clipped, and at worst it will interfere with the scrolling logic as you move it around. Create a separate panel with a depth higher than the scroll view, and put your quick return header there. Position the header using math by taking UIPanel's clipOffset into consideration (or just finalClipRegion). It's not a trivial task though, so I can't offer any specifics.

It would be far easier to simply show or hide the header based on some widget's isVisible status.

heisenburger

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: How to get Top of elements ScrollView from another panel
« Reply #4 on: February 22, 2014, 09:01:45 PM »
You wouldn't make your quick return header a part of the scroll view. It needs to be separate, or at best it will be clipped, and at worst it will interfere with the scrolling logic as you move it around. Create a separate panel with a depth higher than the scroll view, and put your quick return header there. Position the header using math by taking UIPanel's clipOffset into consideration (or just finalClipRegion). It's not a trivial task though, so I can't offer any specifics.
Thanks for the steps -- this is in fact what I've already done!  Perhaps I've overcomplicated my question:  How can I get the position of the topmost object drawn in the scrollview's panel (without knowing what the object is)?  Appreciate your looking into my special case but really I just need to know this one part in order to finish what I've started :)

heisenburger

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: How to get Top of elements ScrollView from another panel
« Reply #5 on: February 22, 2014, 10:02:40 PM »
OK - finally got it :)

NGUIMath.CalculateRelativeWidgetBounds (Transform root, Transform child)

It was right in front of me but I missed it.  Thanks for the help ArenMook. I hope this thread is helpful for anyone trying to do something similar to what I am!