Author Topic: UICenterOnChild / Scrolling List help  (Read 2413 times)

Frieza

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
UICenterOnChild / Scrolling List help
« on: August 07, 2016, 05:37:09 AM »
EDIT: Solved

Hi there,

I'm looking for some advice on how to best achieve an effect. I have a draggable scrolling list with a UICenterOnChild script thrown into the mix, I want to mainly gain the effect of giving the user the freedom to drag the list (no matter how long) but also switch to keyboard or joypad and cycle through the options, with the menu re-centering every time they do (i.e. so the list scrolls with their options rather than their selection dropping off the bottom of the viewable area).

This works just fine, I have all of that set up and functioning, but I want a bit of clamping in the mix for when you reach the top of long lists (or indeed if your list is so short it doesn't warrant dragging at all).

This particular menu goes from top-to-bottom with the first item always at the top of the visible area until scrolled off-screen. However, centering brings the entire menu down, with the top item in the center of the visible area. Ideally, this will clamp to be at the top of the visible area rather than at the center until we're low enough in the list that we want to have items centered in the list. Currently, recentering leaves a lot of white space at the top of the menu when you scroll right to the top which is an undesired effect.

Any ideas how I might achieve the clamping I'm looking for? Advice is most appreciated. Thanks!

Edit: I partially solved this -
I have an anchored widget in the middle that is triggered only OnStart - this allows me to get a transform in the center of the viewable space that I can center upon. If I select an item that is within the top of the list, I instead center on this than the actual item in the list, so it 'sticks' to the top. I'm now turning the centering on/off depending if you're using a joypad or a mouse (so no centering for the mouse drag) - this almost achieves what I want, but there's an obvious 'jump' between the current item and the static 'center of the top' as you cross the edge, so i'll have to look into having a sliding frame of reference for when you cross this region perhaps.

Edit2: Okay, I fully solved it myself, it was silly to consider 'the bottom' of the viewable area as the point to start natural centering from.

For anyone else who is having the same problem:
I simply run a check for the 'threshold' items before any scrolling ever happens against my anchor. If their transforms Y is either side of the anchor's transform Y, these items are 'the threshold' (e.g. item 3's Y is < the anchor, but item 4 has a Y > the anchor).

So, when you move up the list, if your current selection is one of the items above the threshold (i.e. near the top of the list) select your center-of-screen anchor instead of the item itself. Same sort of idea when scrolling down the list.
« Last Edit: August 07, 2016, 06:11:58 AM by Frieza »