How to know if a Scroll View is showing Scroll Bars?

Is there any way to know if a scroll view is currently showing Scroll Bars in a particular direction (horizontally / vertically)?

I’m using a system that fills in a windows content automatically and I need to know when the content has exceeded the bounds of the scroll view in the window.

void ShowWindow( int id )
{
_scrollPosition = GUILayout.BeginScrollView( _scrollPosition );
{
FillInContent();
}
GUILayout.EndScrollView();
//I need to know at this point if the content has exceeded the bounds.
}

GUI.BeginScrollView takes in 2 parameters which are relevant to your question.

Firstly, the position:Rect parameter defines the size of your scroll view.

Secondly, the viewRect:Rect parameter defines the size of the content inside your scroll view.

Scroll bars will be displayed when your viewRect parameter is larger than the position parameter.

I’ve no idea what you are displaying in the window so I can’t really advise how you’d measure the viewRect but I’m guessing GUIStyle.CalcSize might help you in some way. :wink: