Guilayout box

I want to make a box through the autolayout and punt gui controls in it.

The reference says the following:

Make an auto-layouted box.

This will make a solid box. If you want to make a box with some contents inside, use the style paramenter of one of the subgroup functions (BeginHorizontal, BeginVertical, etc…).

I tried passing BeginVertical as a GuiLayoutoption but unity didnt like it. I also tried the begin vertical before/after the box and the endvertical at finished content, also no good.

Can anyone tell me how i can put controls inside an automatic box?

PS: sorry if this question is already asked but i couldnt find a search function in the forum and there are too much entries to look through.

Post some code so people can see what you’re trying to do.

Have you read this: Unity - Manual: IMGUI Layout Modes

It should explain GUILayout pretty well. :wink:

I did actually read the gui layout multiple times. And also the gui scripting guide. It is just the use of the Guilayout.Box which is confusing.

                // Make an area to contain chat
                GUILayout.BeginArea(window);
                GUILayout.BeginVertical();
                // Add box and a space
                GUILayout.Box("Chat"); //(new Rect(0, 0, window.width, window.height), "Chat");

                // Show screen with chat
                GlobalChatWindow();

                GUILayout.EndVertical();

                // End created area
                GUILayout.EndArea();

I want all the controls made in the globalChatwindow function (a scrollview with labels, a textfield and a button) to be INSIDE the box. I commented out the box i previously made with Gui.Box.

I would like to be able to define the controls to go into the box, besides just 1 text you can fit in there.

That is what the manual says on the section. So i tried to use BeginVertical as a layout option which of course failed. Starting beginVertical before or even after the box made the box stop before other controls begin.

My question now is how do i get a scrollview a textfield and a button Inside the Guilayout.box?

You can’t put other controls inside a box created with GUILayout.Box. The GUI elements that can contain other elements are the ones with matching BeginXXX and EndXXX functions (BeginHorizontal, BeginVertical, BeginArea and BeginScrollView.

If the box cant contain anything what would it be used for?

And why do they suggest putting contents inside the box if it is not at all possible:

The quote would lead me to believe there should be a way?

Okay, i see i was being a bit stupid. I am using a scrollview. I styled the scrollview as a box and it looked fine. I have the look of the box and the controls inside :slight_smile:

Thankyou all for the replies

Got the same question -I have absolutely no idea how to use a GUI box and fill it with content. The docs are not clear enough on this topic :frowning:

The docs say:

Using a “style” parameter? “Subgroup functions”? Huh? :shock:

Is there a sample code anywhere that shows how to use such misterious magic boxes?

Since I searched for the same thing and found this thread, I post the answer here. The solution is quite simple:

GUILayout.BeginVertical("MyBox", GUI.skin.box);
GUILayout.Space(20); // spacer to account for the title
// ... your box content ...
GUILayout.EndVertical();
3 Likes