Author Topic: Automatically scroll to end of view  (Read 4023 times)

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Automatically scroll to end of view
« on: October 20, 2013, 11:08:08 AM »
I have a scroll panel with a vertical scrollbar which contains a simple label. The label is updated throughout game play.

How can I automatically scroll to the end as text is appended?

  1. if (logLabel.text == "")
  2.         logLabel.text = message;
  3. else
  4.         logLabel.text += "\n" + message;
  5.  
  6. // automatically scroll to end.
  7. // Does not work :(
  8. logScrollbar.value = 1f;
  9.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Automatically scroll to end of view
« Reply #1 on: October 20, 2013, 06:08:23 PM »
UIDraggablePanel.SetDragAmount

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Automatically scroll to end of view
« Reply #2 on: October 20, 2013, 06:21:46 PM »
This is almost working:
  1. if (logLabel.text == "")
  2.     logLabel.text = message;
  3. else
  4.     logLabel.text += "\n" + message;
  5.  
  6. // Automatically scroll to end.
  7. logScroller.SetDragAmount(0, 1, false);
  8.  

It scrolls to the entry before the latest.

  1. Log("A");
  2. Log("B");
  3. Log("C");
  4. Log("D"); // This one is at the bottom
  5. Log("E"); // Need to manually scroll to see this fellow!
  6.  

Any ideas?

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Automatically scroll to end of view
« Reply #3 on: October 20, 2013, 06:29:14 PM »
Side Note: Passing "true" in to update the scrollbars causes the entire scroll panel to shift downwards (like when scroll scale is set to 0).

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Automatically scroll to end of view
« Reply #4 on: October 20, 2013, 06:32:55 PM »
Calling "UpdateScrollbars" manually seems to resolve my issue though:
  1. // Automatically scroll to end.
  2. logScroller.UpdateScrollbars(true);    
  3. logScroller.SetDragAmount(0, 1, false);
  4.  

Thanks for pointing me in the direction of SetDragAmount!!