- Home /
Providing a start location for GUILayout.beginHorizontal ?
Here's the code I have right now:
GUILayout.BeginVertical(textBoxStyle);
GUILayout.BeginHorizontal();
GUILayout.Label("Here's some test text.");
GUILayout.EndHorizontal();
GUILayout.EndVertical ();
This gives me the desired behavior in terms of vertical and horizontal expansion: the text box around the label is automatically sized to contain the label's text. The problem is that it's at the upper left part of the screen.
If I add a GUILayout.BeginArea() and EndArea() to wrap that code, then I can place it wherever I want, but for some reason the desired autosize behavior goes away for the width. The height is correctly autosized, but the width of the text box goes to the full width of the Area, even if the text is shorter than that. I tried putting a ExpandWidth(false) in the BeginVertical, BeginHorizontal, and the Label, but this changed nothing. Why is this undesired behavior happening only for the width of the text box, but not for the height, and how can I fix it?
What happens if you use your style in the Label i.e. GUILayout.BeginLabel("text",textBoxStyle);
ins$$anonymous$$d of the BeginVertical?
How about sticking a BeginHorizontal around the whole lot to tell it that it needs to use the screen width?
use GUILayout.FlexibleSpace
. Sometimes (and irregularly) the automatic spacer for GUILayout
is crappy and doesn't do things like it should. Can't wait till the new UI system comes out XD
The textBoxStyle is just for the textbox background. I'm using BeginHorizontal and BeginVertical because I'm hoping to concatenate multiple labels together, i.e. http://answers.unity3d.com/questions/535695/best-method-for-multiple-styles-within-textbox.html .
I tried putting another BeginHorizontal around the whole thing, but that didn't help.
GUILayout.FlexibleSpace just adds space, right? I need to do the opposite. Right now it's expanding the text box to be bigger than it needs to be. I'm hoping to automatically size the width just like the height is being automatically sized.
If you're using a GUISkin (I assume you are because you have several styles), there's an option in each style for "Stretch Width". Have you tried turning that off?
Your answer
![](https://koobas.hobune.stream/wayback/20220613114120im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Deselecting Textarea when button pressed 1 Answer
How can I clear a textbox and repeat the text with my effect? 0 Answers
How to get a pop-up window floating next to a gameobject? 1 Answer
Simple text in a box - on player collision 2 Answers
How do you get a caret to show in GUILayout.TextField ??? 0 Answers