GUI.Window inside a GUI.ScrollView

Hello, I am trying to place a GUI Window inside a scroll view so that the window will move when when the scroll view is scrolled. My code is basically

scrlpos = GUI.BeginScrollView( … );
GUI.Window ( … );
GUI.EndScrollView();

Currently it seems that it may not be possible to achieve the effect I want with a GUI.Window. Is there any way? Thanks.

GUI.Window are completely seperate containers and form a container for all the rest, they can’t be contained in anything else aside of OnGUI itself

Depending on what you want to do in detail, BeginArea / BeginGroup are what you might actually be looking for (subcontainer within another container like a scrollview)

Here’s a thought that I can’t test at the moment…

You could write a function that ‘clamps’ the window’s position rectangle so that it’s always within the scroll view rectangle.

You could alter the position of the rectangle based on the value of the scroll vector (or by dragging it), then call your clamp function.

If you want to

a. instance a GUI.Window
b. scroll the window both vertically and horizontally
c. make the window dragable

then read this code

	public Vector2 scrollPosition = Vector2.zero;
	
	void OnGUI()
	{
		// Required so that all GUI Controls render relative to (0,0) inside the window
		GUI.BeginGroup(windowRect);
		
		// Call the window
		windowRect = GUI.Window(0, windowRect, DoMyWindow, "Inventory");
		
		GUI.EndGroup();
	}
	
	
	private Vector2 scrollViewVector = Vector2.zero;
	
	void DoMyWindow(int windowID) 
	{
		// Begin the ScrollView (First Rect defines the size of the scrollview, Second Rect defines the size of the view of controls
		// If the size of your controls dont fit into the size of your scrollview then horizontal or vertical scrollbars appear
		scrollViewVector = GUI.BeginScrollView (new Rect (0, 20, inventory_width-5, inventory_height-25), scrollViewVector, new Rect (0, 0, 0, top_offset+entry_pos+25));
		
		// My Controls (Put what you like in here)
		entry_pos=top_offset;
		displayEntries(rootnode);

		// End the ScrollView
		GUI.EndScrollView();
		
		// Add this line to make the window dragable
		GUI.DragWindow (new Rect (0,0, 10000, 20));
    }