GUI Scroll View

Hi, all! I am trying to make a GUI scroll box in a chat box that scrolls ONLY VERTICALLY. I looked up GUI.ScrollView in the reference but I just can’t seem to wrap my head around it.

This is the portion of code I grabbed from the page…

    // An absolute-positioned example: We make a scrollview that has a really large client
    // rect and put it in a small rect on the screen.
    scrollposition = GUI.BeginScrollView (Rect (10,300,100,100),
        scrollposition, Rect (0, 0, 220, 200));
    
    // Make four buttons - one in each corner. The coordinate system is defined
    // by the last parameter to BeginScrollView.
    GUI.Button (Rect (0,0,100,20), "Top-left");
    GUI.Button (Rect (0,180,100,20), "Bottom-left");
    // End the scroll view that we began above.
    GUI.EndScrollView ();
}

This is all fine and dandy, but I have a few questions:
A. Why is it that the first two lines (after the comments) are not connected? what do they do? Does it supply a domain and then a box or what?
B. when I insert my own values, to fit the chat box, nothing shows up. Why?

alt text

Thanks- YA

Ok, it seems you missed some basic syntax rules ;)

The compiler doesn't care for new lines or indent-spaces in the first place (except for single-line comments which are terminated at a new line character). Every script could be written in a single line but that's a total mess to read for humans. That's why we struct our scripts in a way that you can easy read and understand what the script does.

Something like that:

scrollposition = GUI.BeginScrollView (Rect (10,300,100,100), scrollposition, Rect (0, 0, 220, 200));

Can also be written like that:

scrollposition = GUI.BeginScrollView (
                      Rect (10,300,100,100),     // screen position
                      scrollposition,            // current scroll position
                      Rect (0, 0, 220, 200)      // content area
                 );

There's absolutely no difference in those two forms. It's just to avoid long single-line commands so you don't have to scroll sideway to view it.

The scrollview itself is quite simple. the first parameter defines the rectangle on the screen where your scrollview should be displayed and at what size. In your example at position (10, 300) and the size is (100, 100).

The "scrollposition" is a variable that stores the current scrollposition.

The content area (viewrect) is your virtual space inside the scrollview. in this area you define your GUI elements (buttons, labels, ...). From this area you only see a fraction since the viewable size on screen is defined with (100, 100).

If you don't want to scroll sideways you should make your content rectangle's width smaller so it can be displayed completely inside the visible area. The height should be big enough (more than the viewable area) so it gets actually scrolled.