I'm currently doing the following:
scrollPosition = GUI.BeginScrollView( new Rect(0,0,25,100), scrollPosition, new Rect(0,0,100,100) );
As you can see, the height of the scroll view is the same as the view rect. In my mind, this should not generate a vertical scroll bar. However, because the horizontal scroll bar is generated (it takes up vertical space), it then results in the vertical scroll bar appearing. Hence, I need a way to get the height of the horizontal scroll bar so I can add it onto the height of the scroll view to compensate. In Windows lingo, this would be the same as setting the "client rect" size of the scroll view. Is there any way of doing this?
Answer by Molix
Apr 12, 2010 at 08:44 PM
I encountered exactly this issue, and I kind of agree with Cyclops (hard-coding values is not great but in this case I would), though I would make a public member variable so the designer can tweak those Rects and the spacing later if the skin/style changes.
Also you can get the height of the Horizontal Scroll Bar style (e.g. skin.GetStyle("horizontalscrollbar").fixedHeight), though with padding/margins that could probably be changed.
Answer by Cyclops
Apr 06, 2010 at 07:33 PM
I think the viewRect is basically a "client rect". Personally, I would just subtract 20 from the viewRect height, and call it a day :) I realize hard-coding numbers is frowned upon, but how many times is a scrollbar's dimensions likely to change? (Okay, maybe 20 isn't right, play around with it).
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
How can I set the mousewheel scroll speed in a ScrollView?
How can I replace the behaviour of a GUILayout.scrollView on MouseWheel event?
End scrollview c#
Can you have a scrollview inside a textfield?