Search Unity

GUILayout.TextArea fill available height

Discussion in 'Immediate Mode GUI (IMGUI)' started by Dakta, Apr 23, 2010.

  1. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    I have been working on a simple multi line plain text editor for unity, as part of a larger project. I have only run into one problem with the GUI so far, and this has been that my TextArea won't automatically fill all the available vertical space.

    Here's the OnGUI

    Code (csharp):
    1. function OnGUI () {
    2.     //padding for everything
    3.     BeginArea(Rect (10,10,Screen.width-20,Screen.height-20));
    4.  
    5.     // Start whole frame horizontal layout
    6.     BeginHorizontal("Box");
    7.  
    8.     // Start menubar vertical layout
    9.     BeginVertical(Width(100));
    10.    
    11.     // Label the Menu as a menu
    12.     Label ("Menu");
    13.    
    14.     // Make the first button.
    15.     if (Button("Open...")) {
    16.         openSaveType = "open";
    17.         openSaveVisible = true;
    18.         print("just past the window");
    19.     }
    20.  
    21.     // Make the second button.
    22.     if (Button ("Save...")) {
    23.         openSaveType = "save";
    24.         openSaveVisible = true;
    25.         print("just past the window");
    26.     }
    27.     EndVertical();
    28.    
    29.     BeginVertical();
    30.     textAreaString = TextArea (textAreaString);
    31.     EndVertical();
    32.  
    33.  
    34.     EndHorizontal();
    35.     EndArea();
    36.    
    37.     if (openSaveVisible == true) {
    38.         if (openSaveType == "open") {
    39.             openSaveRect = Window (0, openSaveRect, openSaveWindow, "Open...");
    40.         } else if (openSaveType == "save") {
    41.             openSaveRect = Window (1, openSaveRect, openSaveWindow, "Save...");
    42.         }
    43.     }
    44. }
    Any ideas? Or will I have to set it all with height? (I want the box to fill the entire screen (with a 10px gutter) and then the TextArea to fill all that vertical space)
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    I'm not sure why the TextArea doesn't fill all the space, but you will probably find it easier to use the GUI functions (as opposed to GUILayout) if you need to set the controls' positions precisely.
     
  3. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Try doing GUILayout.TextArea (myString, GUILayout.ExpandHeight (true));
     
    Ash-Blue likes this.
  4. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    Ahh, that did it perfectly! Thank you.