Editor - GUILayout.BeginArea does not expand ScrollView

I’m trying to write a node-based editor with some draggable panels in it, a bit like Unity Tutorial Node Editors part 1 [Advanced] - YouTube

The problem I’m having is that when I resize the editor I’d like the area which contains the nodes to scroll but I can’t get it to work :frowning: If I place an Area inside a ScrollView it doesn’t expand the scroll area to accomodate it (like in my image above) if the ScrollView is say 500 x 500 pixels and I place an Area at position 700,700 with a width of 100 x 100 then I’d expect the scroll area to expand to 800 x 800 but it doesn’t :frowning: The only way I found to get around it is to place a hacky Label inside with size 800 x 800.

Consider the following code for a basic editor window. The window should contain a fixed area at position (600,500) with width and height 64 pixels, inside a scrollable area of size (500,400):

public class TestEditor : EditorWindow
{
	Vector2 scrollPos = Vector2.zero;

	[MenuItem("Window/Test")]
	public static void Init()
	{
		var window = EditorWindow.GetWindow(typeof(TestEditor));
		window.ShowTab();
	}

	void OnGUI()
	{

			scrollPos = GUILayout.BeginScrollView(scrollPos, true, true, GUILayout.Width(500), GUILayout.Height(400));
			{
				GUILayout.BeginArea(new Rect(600, 500, 64, 64), GUI.skin.GetStyle("box"));
				GUILayout.EndArea();
			}
			GUILayout.EndScrollView();
  }
}

The problem is that the ScrollView doesn’t seem to acknowledge the existence of the Area inside it… the horizontal scrollbar stays fixed at 500 pixels, and the vertical one is fixed at 400 pixels though it has around 10 pixels of scrollable area. I would expect the scrollable area to expand to include the Area (I’m aiming to be able to drag the area around but constrain it to a scrollable panel).

55526-scroll.jpg

Is there any way I can make this work without some dodgy hack?

I finally fixed this using the Label idea above. Using this.position it will adjust properly when the window is resized -

			float width = this.position.width
			float height = this.position.height;

			float viewWidth = 1024;
			float viewHeight = 768;

			scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(width), GUILayout.Height(height));
			{
				GUILayout.Label("", GUILayout.Width(viewWidth), GUILayout.Height(viewHeight));
				PaintNodes();
			}
			GUILayout.EndScrollView();