Author Topic: Best way to scroll to bottom of UITable at runtime?  (Read 8776 times)

Joe @ ByDesign Games

  • Guest
Best way to scroll to bottom of UITable at runtime?
« on: August 26, 2012, 08:12:49 PM »
Have a UITable whose parent has UIPanel (with clipping) and UIDraggablePanel component.

Am adding content to the UITable at runtime (for a dialog list viewer) so the list gets longer the more the player interacts.

Such, wish to always show the bottom of the list when adding new items.

Read some related threads on this but they seem outdated (Referencing TweenPanel or SetDragAmount()). Event tried setting UIDraggablePanel.Drag to Vector2(0f, 1f) but getting errors galore.

How to best achieve this?

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #1 on: August 26, 2012, 10:11:26 PM »
Aren just helped me with this:
Quote
Scrolling to the end can be done using SpringPanel.Begin(targetPosition), the same way CenterOnChild works (line 90).

In my case the target position to do this was Vector3.zero. It is a static method so you have to pass a reference to the panel you want to move, like so:
  1.         SpringPanel.Begin(this.dragPanel.gameObject, Vector3.zero, 50);
  2.  

Hope that helps you too,

- Rafe
« Last Edit: August 26, 2012, 10:13:01 PM by Rafe »

Joe @ ByDesign Games

  • Guest
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #2 on: August 26, 2012, 10:22:26 PM »
Can you post the full line & context? Am not clear based on what you've said.

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #3 on: August 26, 2012, 10:29:08 PM »
I'm not sure what you mean. That is all of it. Just replace my gameobject with a reference to yours (the draggable panel). I'm using a Grid instead of a table, but from what I have read in the API docs it should work the same way.

  1. SpringPanel.Begin(<insert draggable panel gameObject reference here>, Vector3.zero, 50);

This will add the component and activate it to move the panel.

BY the way, you don't have to use a strength of 50. 8 is a nice slow smooth motion. 50 is just faster.

Joe @ ByDesign Games

  • Guest
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #4 on: August 26, 2012, 10:39:25 PM »
Yes, thank you, that was the detail i was asking for.

Unfortunately it does not resolve the issue here. Are you sure you were trying to do the same thing?

Seems Vector3.zero does nothing to scroll to the bottom of UITable and a higher value scrolls all content to the position (instead of waiting until the table is "full")

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #5 on: August 27, 2012, 01:50:45 AM »
Oh I forgot I rotated my Grid 180 in Z so zero was at the bottom and new items get added to the top. I have a pretty special use case, but it works for what I need. Sorry if it didn't help.




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #6 on: August 27, 2012, 08:17:38 AM »
The target for SpringPosition should be the local position of where you want to move it, not zero. For example if you wanted to position it at 100 pixels along the Y, it would be Vector3(0f, 100f, 0f).

Joe @ ByDesign Games

  • Guest
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #7 on: August 27, 2012, 09:20:59 AM »
So how to calculate the bottom that value to represent the bottom of the table?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #8 on: August 27, 2012, 12:24:45 PM »
I'm not sure I understand what you're asking. CalculateRelativeWidgetBounds tells you the bounds, which gives you the bottom position to spring to.

Joe @ ByDesign Games

  • Guest
Re: Best way to scroll to bottom of UITable at runtime?
« Reply #9 on: August 27, 2012, 12:30:13 PM »
Yes, that is what i'm asking :)

So to sum up, the best way to scroll to bottom of UITable at runtime is:
  1. SpringPanel.Begin(tableGameObject, new Vector3 (0f, CalculateRelativeWidgetBounds (tableGameObject.transform).size.y, 0f), 8f);
« Last Edit: August 27, 2012, 12:55:39 PM by Joe @ ByDesign Games »