- Home /
GUILayout.MinHeight and EditorGUILayout.BeginScrollView not respecting layout options.
I suspect I’m just misunderstanding what the various GUILayoutOptions are supposed to do. I’m not actually looking for a workaround, my research has found a few of those; I’m just looking for help to clear up my confusion.
I’d like a fairly simple text control in the editor.
It should always be at least 60 units high, if all the text can fit vertically.
If the text cannot fit vertically in 60 units, it should expand vertically, to the height of the text, but at most 500 units.
If the text is larger, vertically than 500 units, a scroll bar should be shown.
Now I had EXPECTED the following code to create an extreemly simple control like that:textScrollPosition = EditorGUILayout.BeginScrollView(textScrollPosition, GUILayout.ExpandHeight(true)); mytext = EditorGUILayout.TextArea((mytext, GUILayout.MinHeight(60), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(500)); EditorGUILayout.EndScrollView();
It does NOT work as expected, so I did some troubleshooting, and I’m clearly not understanding the results, or perhaps, the intention of these functions/parameters:
Let’s start with GUILayout.MinHeight
. I would expect this to specify the minimum height a control should be. I would NOT expect it to affect the maximum height of the control. But the following code displays a text area that is 60 units high: All the time, regardless of the text.
mytext = EditorGUILayout.TextArea((mytext, GUILayout.MinHeight(60), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(500));
If I exclude the MinHeight, it expands/contracts properly based on the text. But it CAN also be less than 60 unit high, which is what I wanted to avoid.
What am I misunderstanding about the GUILayout.MinHeight option?
I’m also unclear what’s going on with the layout system when I use EditorGUILayout.BeginScrollView
. If I enclose the above text area, in a scroll view, the height of the text box changes to only two lines of text. Even if I assign the GUILayout.ExpandHeight(true)
option, to the scroll view, it still limits the text to two lines.
If I follow the limited examples in the docs, and use a SPECIFIC height option, for the scrollView, like GUILayout.Height(300): THIS option IS respected by the scroll view.
What am I misunderstanding about the "automatically layouted" scroll view?
I’ve seen other answers that go and compute the height of the text and stuff like that, to feed a fixed GUILayout.Height option to the ScrollView and Text Area: and I can certainly do this as a last resort, but I’d like an explanation of what it is that I’m not understanding in the GUILayout system. What incorrect assumptions am I making?
Answer by randomdragon · Aug 04, 2021 at 01:38 AM
This may help: https://answers.unity.com/questions/648971/why-is-guilayoutminheight-applying-a-maximum-heigh.html
Your answer
Follow this Question
Related Questions
Setting height via GUILayout.Height() has no effect to BeginVertical in Inspector 0 Answers
Odd GUILayout Placement 0 Answers
EditorGUILayout split view (resizable scroll view) 2 Answers
What is the difference between editorguilayout and guilayout? 1 Answer
EditorGUI, EditorGUILayout, GUI, GUILayout... pshhh... WHEN TO USE WHAT?! 3 Answers