Before updating to Windows 10 you may need to return your Pro license. More information here

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.

more ▼

asked Jul 08, 2011 at 06:41 AM

avatar image

455 4 7 16

An update: I have still had no luck. I am tempted to either use my own GUI dragable box function, although that will be a pain as well as you'd also have to change the GUI style when it is selected. My other idea is to offset the GUI window by the scroll view position in accordance to the scroll view's rects. This would also be very annoying.

Jul 08, 2011 at 11:04 PM Lab013
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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)

more ▼

answered Jul 10, 2011 at 11:11 PM

avatar image

3.7k 4 11 41

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jul 11, 2011 at 05:36 AM

avatar image

3.8k 37 48 93

(comments are locked)
10|3000 characters needed characters left

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
         // Call the window
         windowRect = GUI.Window(0, windowRect, DoMyWindow, "Inventory");
     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)
         // End the ScrollView
         // Add this line to make the window dragable
         GUI.DragWindow (new Rect (0,0, 10000, 20));

more ▼

answered Nov 17, 2012 at 03:25 PM

avatar image

36 4 4 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jul 08, 2011 at 06:41 AM

Seen: 3249 times

Last Updated: Nov 17, 2012 at 03:25 PM