GUI.VerticalScrollbar usage?

Hi guys,

I figured out that GUI.VerticalScrollbar comes without the nasty scrollView bugs (well, at least without all of them) :).

So I wanna try to use it as a (temporary) solution when writting my own scrollView.

OK, let’s read the class description for a start:

Well, I’ll just ignore the last sentence, since I do not want to use scrollViews for sure. :slight_smile:

Now about parameters:

Not very clear what the last 4 parameters do.

size: How much we see?” - I don’t quite get it. :slight_smile:

Could somebody please elaborate on usage on this thing? Which parameters do I have to input to get desired percentages in the example, and what would the output value range be (amounts in the example).

Because I did some measuring on screen and figured out that the scrollbar thumb doesn’t have exactly 10%, 20% of height.

Thanks!

Here’s the code I’m using and output I’m getting:

public class VerticalScrollbarTest : MonoBehaviour
{   
    private float _amount1;
    private float _amount2;
    private float _amount3;
    private float _amount4;
    private float _amount5;

    void OnGUI() {

        if (_w < 0)
            _w = GUI.skin.GetStyle("verticalscrollbar").fixedWidth;

        _amount1 = GUI.VerticalScrollbar(new Rect(50, 50, _w, 400), _amount1, 100, 500, 0); // I want 20% of the size here
        _amount2 = GUI.VerticalScrollbar(new Rect(50 + 50, 50, _w, 400), _amount2, 200, 500, 0); // I want 40% of the size here
        _amount3 = GUI.VerticalScrollbar(new Rect(50 + 50 * 2, 50, _w, 400), _amount3, 500, 500, 0); // I want 100% of the size here
        _amount4 = GUI.VerticalScrollbar(new Rect(50 + 50 * 3, 50, _w, 400), _amount4, 100, 1000, 0); // I want 10% of the size here
        _amount5 = GUI.VerticalScrollbar(new Rect(50 + 50 * 4, 50, _w, 400), _amount5, 200, 1000, 0); // I want 20% of the size here
    }
}

Here’s what I found out:

GUI.VerticalScrollbar
is very similar to GUI.VerticalSlider, in a way that - if we ignore the scrollbar’s thumb height - it behaves as a slider!

However, when scrollbar having a considerable height, it messes with the selectable range: you cannot get all the values in the min-max range as the output.

But, when the thumb size is kept at minimum (a few pixels height), then you can select all the values.

This made me think, so I came up with a formula:

_amount = GUI.VerticalScrollbar(_scrollbarRect, _amount, _thumbHeight, _min, _max + _thumbHeight);

… where the _thumbHeight (the height of the scrollbar thumb) is being added to the max value.

This way you could select all the given values. :slight_smile: