Search Unity

Scrolling TextArea

Discussion in 'Immediate Mode GUI (IMGUI)' started by capnbishop, May 4, 2009.

  1. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    How would one go about creating a scrolling text area with a variable quantity of text?

    I'm used to high level GUI elements, where I could drop in a text area and turn on the vertical scroll bar. Then the scroll bar would automatically activate and adjust when the text area fills up.

    I'm having a hard time finding a convenient way to handle scrolling text areas in Unity. Is it really necessary to calculate how much space a chunk of text will fill up in order to determine it's height, just to implement a variable scroll bar?
     
  2. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
  3. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    Cool, got it. I forgot all about the GUILayout class. Is there a way to determine what the maximum possible scroll is for a scroll view? For instance, if I want a scrollable text field to always be scrolled to the bottom.
     
  4. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    Nevermind, I figured it out. I set the y value of the scroll vector to Mathf.Infinity. That did the trick. Thanks for you help.
     
  5. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    what does that line look like?
     
  6. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    I think it was something like this:

    Code (csharp):
    1. BeginScrollView (Vector2(0, Mathf.Infinity));
    The first value passed to BeginScrollView is a Vector2 for the x and y position of where the view is scrolled. It's not necessary to know what the max scroll value is, because the view won't go past the maximum scrolled point. By setting the y value to Math.Infinity, you can ensure that it will always be scrolled to the bottom.

    If you want to bother with horizontal scrolling, you'd probably need to do something like this:

    Code (csharp):
    1. var scroll : Vector2;
    2.  
    3. function whatever () {
    4.     if (!scroll) { scroll = new Vector2(0,0); }
    5.     scroll = BeginScrollView(Vector2(scroll.x, Mathf.Infinity));
    6. }
    - John
     
  7. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    thanks!!!

    got that working.

    only call it on hit return/enter and works like a charm.
    rest of the time, user can scroll wherever.

    I really appreciate your assistance.
     
  8. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    Glad I could help!