x


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 '11 at 06:41 AM

Lab013 gravatar image

Lab013
400 1 2 10

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 '11 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 '11 at 11:11 PM

Dreamora gravatar image

Dreamora
3.4k 1 4 27

(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 '11 at 05:36 AM

jahroy gravatar image

jahroy
3.6k 14 19 48

(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
       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));
    }

more ▼

answered Nov 17 '12 at 03:25 PM

GXMark gravatar image

GXMark
11 2 2 2

(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

By RSS:

Answers

Answers and Comments

Topics:

x5110
x103

asked: Jul 08 '11 at 06:41 AM

Seen: 2463 times

Last Updated: Nov 17 '12 at 03:25 PM