Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

GUI foldout only opening when the little arrow is clicked

Discussion in 'Immediate Mode GUI (IMGUI)' started by Halleflux, Jul 17, 2013.

  1. Halleflux

    Halleflux

    Joined:
    Mar 18, 2013
    Posts:
    2
    Code (csharp):
    1.  
    2. showFoldout = EditorGUILayout.Foldout(showFoldout, "Foldout");
    3. if (showFoldout)
    4. {
    5.     //code
    6. }
    7.  
    For some reason, the foldout menu will only open when the tiny little arrow on the left side is clicked, not when any part of the row is clicked. Does anyone know how to fix this? Please do not respond with Javascript. I only work in C#.
     
  2. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    You can create your own foldout. It is nothing complicated:

    Code (csharp):
    1. private bool _expanded;
    2.  
    3. void OnGUI() {
    4.     EditorGUILayout.BeginVertical();
    5.     _expanded = GUILayout.Toggle(_expanded, "Click to " + _expanded ? "collapse" : "expand", GUILayout.ExpandWidth(true));
    6.     if (_expanded) {
    7.         GUILayout.Label("The inner stuff");
    8.     }      
    9.     EditorGUILayout.EndVertical();
    10. }
    Additionally, you could style your foldout button to look nothing like the button. Check out the bluish panels in this video. I made these using the button as described above. The complete panel header is click-able, instead of the tiny foldout arrow. :)
     
  3. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    thanks DKozar,

    I just added "Foldout" as the GUIStyle. ;D

    Code (csharp):
    1.  
    2.         EditorGUILayout.BeginVertical();
    3.        
    4.         _expanded = GUILayout.Toggle( _expanded, "Click to " + (_expanded ? "collapse" : "expand"), "Foldout", GUILayout.ExpandWidth(false));
    5.        
    6.         if (_expanded) {           
    7.             GUILayout.Label("The inner stuff");        
    8.         }      
    9.        
    10.         EditorGUILayout.EndVertical();
    11.  
     
    Bunny83 likes this.
  4. noio

    noio

    Joined:
    Dec 17, 2013
    Posts:
    244
    Insanely old topic but since I ended up here through search:

    use this:
    Code (CSharp):
    1. EditorGUILayout.Foldout(toggleOnLabelClick: true)