Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

ScrollView not expanding and items are being cut off

Discussion in 'Immediate Mode GUI (IMGUI)' started by vulician, Apr 24, 2016.

  1. vulician


    Dec 12, 2012
    I'm currently developing a TreeView extension that I'm going to release for free but I am having some problems getting everything to display correctly. This is the first time I've used the Editor GUI calls, so I'm not sure if I'm using them correctly.

    First, the scroll view does not expand its scrollbar horizontally to fit the content that is placed inside of it. I am currently using GUILayout.Width, but I even tried to use GUILayout.MinWidth. But it seems to truncate all content that goes past its edge rather than expanding itself so the use can scroll to it.

    Secondly, for some reason, it doesn't to show the whole string when displaying. As seen below, the phrase "A really long name" gets cut off after the L in one line, and the M gets cut in half in another. I'm not sure at all what is causing this.

    Code (csharp):
    1. public void Show(float width, float height) {
    2.    scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Width(width), GUILayout.Height(height));
    4.    DrawFolds(roots);
    6.    EditorGUILayout.EndScrollView();
    7. }
    9. private void DrawFolds(List<FoldObj> folds) {
    10.    foreach (FoldObj fold in folds) {
    11.      Foldout(fold);
    13.      // If the foldout is open
    14.      if ( {
    15.        // Increase the indentation level and draw its children
    16.        EditorGUI.indentLevel++;
    17.        DrawFolds(fold.children);
    18.        EditorGUI.indentLevel--;
    19.      }
    20.    }
    21. }
    23. private void Foldout(FoldObj foldObj) {
    24.    EditorGUI.BeginChangeCheck();
    26.    Rect foldRect = EditorGUILayout.GetControlRect(true, 16, EditorStyles.foldout);
    28.    // If we are releasing a click and we are inside the rectangle
    29.    if (Event.current.type == EventType.MouseUp && foldRect.Contains(Event.current.mousePosition)) {
    30.      // If we are allow to select roots
    31.      if (canSelectRoots) {
    32.        foldObj.selected = !foldObj.selected;
    34.        // Handle the selection or deselection of this item
    35.        if (selectFunction != null && foldObj.selected) {
    36.          selectFunction(foldObj);
    37.        } else if (unselectFunction != null && !foldObj.selected) {
    38.          unselectFunction(foldObj);
    39.        }
    40.      }
    41.    }
    43.   // If this item has children then display it as a foldout, else display it as a label
    44.    if (foldObj.children.Count > 0) {
    45. = EditorGUI.Foldout (foldRect,, foldObj.title);
    46.    }  else {
    47.      EditorGUI.LabelField (foldRect, foldObj.title);
    48.    }
    50.    EditorGUI.EndChangeCheck();
    51. }
    I'm at a loss for debugging these errors, does anyone have any thoughts how to fix these issues?
  2. wesleywh


    Jun 8, 2014
    I know this is old but this is the first thing that comes up on google. All you need to do to make this work in ANY size is make sure your child transform scale is set to 1. So when you instantiate a child object in your menu just run a line like the following:
    Code (CSharp):
    1. childobject.transform.localScale = new Vector3(1,1,1);
    and make sure its a child of the content component in your scroll view.
  3. Madgineer


    Jan 1, 2015
    This looks like EditorGUI code not GUI code, They may not have access to scale variables