- Home /
How to disable horizontal scrollbar in GUILayout scroll view?
I've already read the documentation of the GUILayout.BeginScollView. It is just that I don't understand on how to apply the "alwayShowHorizontal" to false. Here's my code :-
scrollPosition = GUILayout.BeginScrollView(scrollPosition,GUILayout.Width (Screen.width*30/160), GUILayout.Height(Screen.width*38/160-Screen.height*1/25));
Thank You.
----------Edited to insert image-------- This is the result I get:-
Always show horizontal will default to false if you don't set it.
@Gizmoi, above I uploaded the result that I get. According to my code I didn't set the parameters, didn't I?
Do you want to just hide the scrollbar or to prevent the scrollview from scrolling horizontally?
If you want to hide it, just use a custom GUIStyle which doesn't contain an image for the background / thumb...
Answer by Baalhug · Feb 04, 2014 at 03:25 PM
If you dont want horizontal scrollbar to show, then your inside rect width must be lower than the rect containing it. This means:
When you call GUI.BeginScrollView you must declare 2 rects (http://docs.unity3d.com/Documentation/ScriptReference/GUI.BeginScrollView.html) The goal of scrollview is to let you draw GUI elements bigger than the area you have to show them, and this is only possible by using scrollbars, as you may understand. So you declare a rect defining the area you have, and another rect defining the real size of your gui content (window, or whatever). Now, if height of the real area is bigger than the display area (change word area by rect, in practise) then a vertical scrollbar will show. If not, you can force it to show by using alwaysShowVertical. The same happens for width.
Conclussion. The only way to avoid horizontal scrollbar shows in scrollview is by defining a rect for the real content equal or smaller than the rect for display. Otherwise, some content would be hidden with no chance to see it.
Just uncheck the Horizontal movement. While the Content and child objects works in theory. It doesn't always work depending on the ScrollViews property
Answer by Ramy-TL · Feb 28, 2017 at 07:51 AM
I use
scrollPos = GUILayout.BeginScrollView(scrollPos, false, false, GUIStyle.none, GUI.skin.verticalScrollbar);
I hope this helps
made me sighn in just to upvote this, thanks heaps.
Same. :) In September 2020 the syntax is
EditorGUILayout.BeginScrollView(scrollPosition, GUIStyle.none, GUI.skin.verticalScrollbar)
But this is still the best answer.
Answer by Gizmoi · Feb 05, 2013 at 03:08 PM
float width = Screen.width * 30 / 160;
float height = Screen.width * 38 / 160 - Screen.height * 1 / 25;
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUILayout.Width(width), GUILayout.Height(height));
That will set alwaysShowHorizontal to false and alwaysShowVertical to be true.
Thanks! Although I now realized that set it to "true" the option only force the scroll bar to appear before content is out of the area. By default(false) it only appears after the content breach the border. So that means that force disabling it is not possible. At least now I know how to use the extended parameter. Thanks again!