ScrollView not expanding and items are being cut off

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.

public void Show(float width, float height) {
   scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Width(width), GUILayout.Height(height));
  
   DrawFolds(roots);
  
   EditorGUILayout.EndScrollView();
}

private void DrawFolds(List<FoldObj> folds) {
   foreach (FoldObj fold in folds) {
     Foldout(fold);

     // If the foldout is open
     if (fold.open) {
       // Increase the indentation level and draw its children
       EditorGUI.indentLevel++;
       DrawFolds(fold.children);
       EditorGUI.indentLevel--;
     }
   }
}

private void Foldout(FoldObj foldObj) {
   EditorGUI.BeginChangeCheck();
  
   Rect foldRect = EditorGUILayout.GetControlRect(true, 16, EditorStyles.foldout);

   // If we are releasing a click and we are inside the rectangle
   if (Event.current.type == EventType.MouseUp && foldRect.Contains(Event.current.mousePosition)) {
     // If we are allow to select roots
     if (canSelectRoots) {
       foldObj.selected = !foldObj.selected;

       // Handle the selection or deselection of this item
       if (selectFunction != null && foldObj.selected) {
         selectFunction(foldObj);
       } else if (unselectFunction != null && !foldObj.selected) {
         unselectFunction(foldObj);
       }
     }
   }

  // If this item has children then display it as a foldout, else display it as a label
   if (foldObj.children.Count > 0) {
     foldObj.open = EditorGUI.Foldout (foldRect, foldObj.open, foldObj.title);
   }  else {
     EditorGUI.LabelField (foldRect, foldObj.title);
   }

   EditorGUI.EndChangeCheck();
}

I’m at a loss for debugging these errors, does anyone have any thoughts how to fix these issues?

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:

childobject.transform.localScale = new Vector3(1,1,1);

and make sure its a child of the content component in your scroll view.

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