Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: kruncher on October 20, 2013, 11:08:08 AM

Title: Automatically scroll to end of view
Post by: kruncher 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.  
Title: Re: Automatically scroll to end of view
Post by: ArenMook on October 20, 2013, 06:08:23 PM
UIDraggablePanel.SetDragAmount
Title: Re: Automatically scroll to end of view
Post by: kruncher 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?
Title: Re: Automatically scroll to end of view
Post by: kruncher 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).
Title: Re: Automatically scroll to end of view
Post by: kruncher 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!!