- Home /
Why is GUILayout.MinHeight applying a maximum height to my element?
See title.
Observe image.
GUILayout.MinHeight is applying a maximum height to my label. I need to have vertically-expanding labels, using Layout functions. What is broken, and how do I work around it?
https://www.dropbox.com/s/2iwx5hr5gxzdp4d/malfunctioning%20minheight.png
Answer by RudyTheDev · Feb 24, 2014 at 08:14 PM
Tried this and got the same, but I'm not sure that it is MaxHeight that gets set. Rather--I guess--Unity thinks MinHeight means clipping labels over the min height is okay when other elements don't fit. Because removing MinHeight option works for me and the label is never clipped (and adding GUILayout.MaxHeight(500f) changes nothing). In other words, label's default min height seems to be the full text height, while you allowed it to get clipped down to 16f.
I guess you should remove MinHeight; or if not, then calculate the text size with GUILayout.MinHeight(GUI.skin.label.CalcSize(new GUIContent("Hello\nBye\nSup")).y)
I'm not using up all the available space, but I know layout functions like to get confused sometimes so that's probably exactly what's happening.
Answer by kami1339 · Apr 05, 2019 at 08:36 AM
Solved!
public Image YourImageOrRawimage;
YourImageOrRawimage .GetComponent<RectTransform>().sizeDelta = new Vector2( minWidth, minHeight);
Don't forget it >using UnityEngine.UI;
This question was about Unity's I$$anonymous$$GUI system and the GUILayout system. Not the new UI system. This answer is off topic.
Your answer
Follow this Question
Related Questions
How do i get size in pixels of a GUI.Label for chat construction purpose ? 2 Answers
EditorGUI, EditorGUILayout, GUI, GUILayout... pshhh... WHEN TO USE WHAT?! 3 Answers
EditorGUI like light explorer window 1 Answer
Drawing several BeginArea inside a BeginScrollview (GUILayout) produces an unexpected behaviour 1 Answer