Search Unity

Hide BeginScrollView scrollbars

Discussion in 'Immediate Mode GUI (IMGUI)' started by luisanton, Sep 1, 2009.

  1. luisanton

    luisanton

    Joined:
    Aug 25, 2009
    Posts:
    325
    Hello!

    I am trying to use GUI.BeginScrollView, which already works perfectly, but I don't want scrollbars. Thus, I want to change their Style so they become invisible (the reason for this is that I want to control the scroll using GUI.ScrollTo)

    According to http://unity3d.com/support/documentation/ScriptReference/GUI.BeginScrollView.html, you can change the scrollbar style with this constructor:

    Code (csharp):
    1. static function BeginScrollView (position : Rect, scrollPosition : Vector2, viewRect : Rect, alwaysShowHorizontal : bool, alwaysShowVertical : bool, horizontalScrollbar : GUIStyle, verticalScrollbar : GUIStyle) : Vector2
    However, if GUIStyle is used, I get the following warning: "Unable to find style 'rightbutton' in skin 'GameSkin' Repaint". While it works and scrollbars become invisible, I don't think it's a good idea to leave this warning there...

    Then I though that it may be an error, that it's not expecting a GUIStyle but a GUISkin. Effectively, if I use a GUISkin this warning dissapears... but the scrollbars are there. And I just cannot manage to change their style (horizontalscrollbarwhatever) so they become invisible, even if I set all heights and widths to zero and remove all textures.

    So my questions are

    1) how could I change scrollbar styles so they are not shown?
    2) should I just ignore that warning? (I tried with null GUIStyles, but that throws an error)

    Thank you!
     
  2. olkeencole

    olkeencole

    Joined:
    Oct 2, 2009
    Posts:
    17
    It took me sometime to find this out by scouring the forum as I needed this tidbit of info myself.

    If you use
    Code (csharp):
    1. new GUIStyle()
    in place of the GUIStyle parameters, the scrollbars will not show up.

    This is what I have have:

    Code (csharp):
    1. scrollPosition = GUI.BeginScrollView (Rect (10,300,100,80), scrollPosition, Rect (0, 0, 450, 50), new GUIStyle(),new GUIStyle());
     
  3. gurpreet

    gurpreet

    Joined:
    Jan 21, 2010
    Posts:
    2
    I tried that and it keeps crashing the application.

    scrollViewVector = GUI.BeginScrollView (Rect (0, 0, 320, 480), scrollViewVector, Rect (0, 0, 320, 820), new GUIStyle(),new GUIStyle());

    Program received signal: “SIGSEGV”.


    Does anyone have a solution on how to get no scroll bars?
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Hi, welcome to the forum!

    Please can you report this as a bug (menu: Help > Report A Problem). There may be a simple solution, but the crashing is cause for concern.
     
  5. gurpreet

    gurpreet

    Joined:
    Jan 21, 2010
    Posts:
    2
    Yes I did submit the bug, I just hope someone will know the work around for this. Is there another way to have a touch scrollable gui view without scroll bars? Or was this the only way?
     
  6. matthewminer

    matthewminer

    Joined:
    Aug 29, 2005
    Posts:
    331
    Use a custom GUISkin which has all the images, padding, margins, etc. set to 0 for the scrollbars. The scrollview will be able to find "rightbutton" and other elements just fine, they will just be set to display nothing.
     
    yashpal likes this.
  7. Paul Ruff

    Paul Ruff

    Joined:
    Dec 28, 2010
    Posts:
    1
    Thanks a lot, this works for me:

    var scrollbarStyle = new GUIStyle(GUI.skin.horizontalScrollbar);

    scrollbarStyle.fixedHeight = scrollbarStyle.fixedWidth = 0;
     
    yashpal likes this.
  8. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Alternatively you may want to use GUIStyle.none to hide GUI elements.
     
  9. Sebek

    Sebek

    Joined:
    Jul 27, 2012
    Posts:
    2
    Hy guys, I'm trying to build a scrollview without the scrollbars, and i have tried all of the methods recommended by you guys and none of them work properly (no offense :p)
    - the ones with new GUIStyle(),new GUIStyle() work but i get A LOT of warnings that cause fps drop (the scrollview is for a chat window in a game)
    - the solution with "scrollbarStyle.fixedHeight = scrollbarStyle.fixedWidth = 0;" keeps the warnings from poping up, put there is still a scrollview scrollbar visible, deformed and ugly, but still visible.
    Any help would be very much appreciated .


    PS: (i'm using unity 3.4.2)
     
  10. Kazca

    Kazca

    Joined:
    Oct 10, 2011
    Posts:
    4
    You can use this class from the unity wiki (Currently down at the moment) to permanently hide the scrollbars

    Code (csharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections.Generic;
    4.  
    5. public static class GUIX
    6. {
    7.     public static Vector2 BeginScrollView(
    8.         Rect position,
    9.         Vector2 scrollPosition,
    10.         Rect contentRect,
    11.         bool useHorizontal,
    12.         bool useVertical,
    13.         GUIStyle hStyle,
    14.         GUIStyle vStyle)
    15.     {
    16.        
    17.         Vector2 scrollbarSize = new Vector2(hStyle.CalcSize(GUIContent.none).y,vStyle.CalcSize(GUIContent.none).x);
    18.         Rect viewArea = position;
    19.         if (useHorizontal)
    20.             viewArea.height -= scrollbarSize.x;
    21.         if (useVertical)
    22.             viewArea.width -= scrollbarSize.y;
    23.         if (useHorizontal)
    24.         {
    25.             Rect hScrRect = new Rect(position.x, position.y + viewArea.height, viewArea.width, scrollbarSize.x);
    26.             scrollPosition.x = GUI.HorizontalScrollbar(hScrRect,scrollPosition.x,viewArea.width,0,contentRect.width);
    27.         }
    28.         if (useVertical)
    29.         {
    30.             Rect vScrRect = new Rect(position.x + viewArea.width, position.y, scrollbarSize.y, viewArea.height);
    31.             scrollPosition.y = GUI.VerticalScrollbar(vScrRect,scrollPosition.y,viewArea.height,0,contentRect.height);
    32.         }
    33.         GUI.BeginGroup(viewArea);
    34.         contentRect.x = -scrollPosition.x;
    35.         contentRect.y = -scrollPosition.y;
    36.         GUI.BeginGroup(contentRect);
    37.         return scrollPosition;
    38.     }
    39.  
    40.     public static Vector2 BeginScrollView(
    41.         Rect position,
    42.         Vector2 scrollPosition,
    43.         Rect contentRect,
    44.         bool useHorizontal,
    45.         bool useVertical)
    46.     {
    47.         return BeginScrollView(position, scrollPosition, contentRect, useHorizontal, useVertical, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar);
    48.     }
    49.  
    50.     public static void EndScrollView()
    51.     {
    52.         GUI.EndGroup();
    53.         GUI.EndGroup();
    54.     }
    55. }
     
  11. Ruslan Krohalev

    Ruslan Krohalev

    Joined:
    Oct 17, 2012
    Posts:
    2
    This works for me:

    // hide vertical scrollbar
    GUIStyle verticalScrollbar = GUI.skin.verticalScrollbar;
    GUI.skin.verticalScrollbar = GUIStyle.none;

    // show scrollview

    // restore vertical scrollbar
    GUI.skin.verticalScrollbar = verticalScrollbar;
     
  12. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    Just noticed that the guy is instantiating new GUIStyle every frame... FPS drop and crashes? Well.. :)

    You should really do it only once (for static values): everything that has a "new" keyword should go outside of the OnGUI method:

    Code (csharp):
    1. public class YourComponent: MonoBehaviour {
    2.     private Rect _position = new Rect (10, 300, 100, 80);
    3.     private Rect _viewRect = new Rect (0, 0, 450, 50);
    4.     private Vector2 _scrollPosition;
    5.     private GUIStyle _horizontalScrollbarStyle;
    6.     private GUIStyle _verticalScrollbarStyle;
    7.    
    8.     void Start() {
    9.         _horizontalScrollbarStyle = new GUIStyle();
    10.         _verticalScrollbarStyle = new GUIStyle();
    11.     }
    12.  
    13.     void OnGUI() {
    14.         _scrollPosition = GUI.BeginScrollView (_position, _scrollPosition, _viewRect, _horizontalScrollbarStyle, _verticalScrollbarStyle);
    15.     }
    16. }
     
  13. Pigghaj

    Pigghaj

    Joined:
    Mar 2, 2012
    Posts:
    8
    I could not get any of the solutions here to work either. What worked for me was:

    1. Create a new Gui skin, assets->create->gui skin.
    2. Change the textures used in scrollbars to "none". And if you wanna be extra safe, set all the values you can find to 0 too, but just changing the texture should be enough.

    Then in your code just create a GUISkin variable:

    Code (csharp):
    1. var guiSkin : GUISkin;
    Then in the inspector, drag the gui skin you created to the new guiSkin variable, then do:

    Code (csharp):
    1.  
    2. function OnGUI ()
    3.  
    4.     GUI.skin = guiSkin;
    5.  
    6.         // the rest of your gui code here...
    7.  
    8.  
    9.  
    And thats it. No scrollbars. And no need to add anything to BeginScrollView, just leave everything at default.
     
    Last edited: Nov 2, 2012
  14. FraMarSaMi

    FraMarSaMi

    Joined:
    May 13, 2014
    Posts:
    86
    But if I hide the scrollbar then the scrollview not scroll... :(
     
  15. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    127
    m_scrollLeft = GUI.BeginScrollView(m_rectControllerInspector, m_scrollLeft, rectView, false, false, GUIStyle.none, GUIStyle.none);

    Just pass GUIStyle.none
     
  16. Dabartos

    Dabartos

    Joined:
    May 26, 2016
    Posts:
    33
    scrollbar = GUILayout.BeginScrollView(scrollbar, GUIStyle.none, GUIStyle.none); works for me.
     
    LuLusg and melgeorgiou like this.