Author Topic: How do you use UIKeyNavigation with dynamic UITable Contents?  (Read 6271 times)

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
I have a UITable with a scroll view that has button objects dynamically created in it.  Sometimes there is 1 item, other times there are 50 items.  I'm hoping to use UINavigation keys to navigate through the buttons that are available. 

I can't figure out how this should be set up exactly using the native components in NGUI.  Currently, I just procedurally set the up and down to each enabled object, which works fine.  However, the scroll view will not update with the current selection.  The scroll view never changes via UIKeyNavigation, but it works fine if the mouse moves the associated slider.  The only component I can find that could fix this is center on child, which is not desirable funcitonality.  I'm hoping for the basic funcitonality where if you select an item outside of the view (say below), then everything moves up just enough to bring it into view.  How would you recommend fixing this?
« Last Edit: April 04, 2014, 02:30:43 PM by Disastercake »
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do you use UIKeyNavigation with dynamic UITable Contents?
« Reply #1 on: April 04, 2014, 10:31:44 PM »
Write a script that will listen to OnSelect(true). Inside, use SpringPanel.Begin to move the scroll view to the object's position. If you need an example, use UICenterOnClick. It uses SpringPanel if the UICenterOnChild is not available.

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
Re: How do you use UIKeyNavigation with dynamic UITable Contents?
« Reply #2 on: October 13, 2014, 10:51:06 AM »
Hey Aren,

I've finally got back around to trying to work with this.  I was able to implement it with a lot of finagling by creating a top and bottom offset (same number, since the scroll view is centered) and then comparing if an item is on or off screen, and whether it is off screen on the top or bottom then adjusting to only the maximum value  (not just centered) which is determined by taking the center and the offset.

Something that came to mind is that it would be awesome if there was some simple script in NGUI's framework that could identify and achieve this functionality immediately, considering that it is the basic functionality of all operating systems and every list cycling in any game I've ever seen.  Perhaps just a script that can be dragged onto an object called UIScollViewObject.
« Last Edit: October 13, 2014, 05:29:52 PM by Disastercake »
Creator of Soul Saga.
http://www.disastercake.com

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
Re: How do you use UIKeyNavigation with dynamic UITable Contents?
« Reply #3 on: October 13, 2014, 11:19:04 PM »
I'm actually having troubles again with this now.  Is it possible for you to create some example code on how to achieve this functionality?  The thing making this the most difficult is the dynamically expanding list, like an inventory in a RPG.  It's hard to tell where the top and bottom borders are to line them up correctly.
« Last Edit: October 14, 2014, 01:06:26 AM by Disastercake »
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do you use UIKeyNavigation with dynamic UITable Contents?
« Reply #4 on: October 14, 2014, 02:16:53 PM »
Lining up top and bottom borders? Of what?

UICenterOnClick / UICenterOnChild are the examples. SpringPanel.Begin can move the panel to a local position of your choice. Knowing a widget, it has localCorners and worldCorners, either one can be used to calculate the center of the widget to SpringPanel to.