Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GUILayout - Label - adding space extra space between bug.

Discussion in 'Immediate Mode GUI (IMGUI)' started by PulseHunter, Jan 28, 2014.

  1. PulseHunter

    PulseHunter

    Joined:
    Jul 31, 2013
    Posts:
    23
    Hi,

    When i add all my GUIlayout.Label it generate some extra space when i use GUILayout.BeginHorizontal();

    I add a picture at the button :)

    Code (csharp):
    1.  
    2.  
    3.                GUI.BeginGroup(new Rect(5, 5, Screen.width, 5000));
    4.                
    5.                 GUILayout.Label(test1, ScaleFont);
    6.                 GUILayout.Label(test2, ScaleFont);
    7.                 GUILayout.Label(test3, ScaleFont);
    8.  
    9.                 GUILayout.BeginHorizontal();
    10.                 GUILayout.Label(Show[0], ScaleFont, GUILayout.MaxWidth(Screen.width / 16));
    11.                 GUILayout.Label(Show[1], ScaleFont,GUILayout.MaxWidth(Screen.width / 16));
    12.                 GUILayout.Label(Show[2], ScaleFont, GUILayout.MaxWidth(Screen.width / 16));            
    13.                 GUILayout.EndHorizontal();
    14.                
    15.                 GUILayout.Label(test4, ScaleFont);
    16.                 GUILayout.Label(test5, ScaleFont);
    17.                
    18.              
    19.                 GUI.EndGroup();
    20.  
    21.  
    After the 3 images there is more text, i could not just get it within the same screenshot

    Thanks in advance



    View attachment 84325
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    The attachment didn't come through. But I think if you use GUILayout.FlexibleSpace() it will fill out the rest of the horizontal space the way you want. For example:
    Code (csharp):
    1.  
    2. GUILayout.BeginHorizontal();
    3. GUILayout.Label(Show[0], ScaleFont, GUILayout.MaxWidth(Screen.width / 16));
    4. GUILayout.Label(Show[1], ScaleFont,GUILayout.MaxWidth(Screen.width / 16));
    5. GUILayout.Label(Show[2], ScaleFont, GUILayout.MaxWidth(Screen.width / 16));            
    6. GUILayout.FlexibleSpace();
    7. GUILayout.EndHorizontal();
    8.  
     
  3. PulseHunter

    PulseHunter

    Joined:
    Jul 31, 2013
    Posts:
    23
    Hi,
    Thanks for the quick respons :)

    but it did not fix it :(
    It stayed the same.

    "New" picture, but it is the same ...

    $Unity_error.png
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Show[0] - Show[2] are textures, right? Is there extra space on the left and right sides of the textures themselves?

    Is ScaleFont a GUIStyle? If so, try setting margin, overflow, and padding to 0.
     
  5. PulseHunter

    PulseHunter

    Joined:
    Jul 31, 2013
    Posts:
    23
    Show[x] is textures.

    Textures are png and there is no extra space.

    ScaleFont is a GUIStyle, i use so i can interact with it from touch.
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Is there any change if you set margin, overflow, and padding to 0 (zero) in the GUI style?
     
  7. PulseHunter

    PulseHunter

    Joined:
    Jul 31, 2013
    Posts:
    23
    I think i found my own soloution :D

    Code (csharp):
    1.  
    2.  
    3.             int c = 0;
    4.  
    5.             GUI.BeginGroup(new Rect(5, 5, Screen.width, 5000));
    6.             GUILayout.Label(Fareidentifikation, ScaleFont);
    7.             GUILayout.Label("",ScaleFont);
    8.             FareRect = GUILayoutUtility.GetLastRect();
    9.             GUI.EndGroup();
    10.  
    11.             FareRect.x = 20;
    12.             FareRect.y -= FareRect.y/4 ;
    13.             for (int i = 1; i <= Show.Count; i++, c++)
    14.             {
    15.                 Debug.Log("Vectore" + FareRect);
    16.                
    17.                 FareRect.x +=60;
    18.                 FareRect.height =100 ;
    19.                 FareRect.width = Screen.width / 10 ;
    20.                
    21.                
    22.                 GUI.Label((FareRect), Show[c]);
    23.                
    24.             }
    25.