- Home /
GUI's documentation lacks of examples
Hi guys,
I'm quite sad to know that GUI's documentation lacks of basic examples like vertically/horizontally centering objects inside a group, align text inside a label, make bold text, make elements act like resizable etc...
I am desperatly looking for a way to center GUI's inside a GUI.BeginGroup(), and make them occupy 100% of the free space inside that group. I can't find it anywhere.
Thanks!
Answer by ScroodgeM · Aug 21, 2012 at 09:40 PM
with GUI.BeginGroup() you already pass a rect of this group, so you know it's size
to draw a GUI within group to it's 100$ size, just draw in rect (0,0,groupXsize,groupYsize)
to draw a GUI centered inside group, just draw in rect (groupXsize 0.5 - contentXsize 0.5, groupYsize 0.5 - contentYsize 0.5, contentXsize, contentYsize);
if your content is dynamic and you don't know it's size, use GUILayout or this
GUILayout example
void OnGUI() { GUILayout.BeginArea(new Rect(100, 100, Screen.width - 200, Screen.height - 200)); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.Box("me is dynamic text\nand me placed in the center\ndon't use GUI layout if you can 8)"); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndArea(); }
Can you give a simple example of using GUILayout in this very particular case where I want to know the group size that is dynamic?
Thanks!
Your answer
Follow this Question
Related Questions
Problem Trying To Get GUI.Label Centred 2 Answers
Center GUI.Label similar to GUIText? 2 Answers
How to make a GUI Label always in the center 1 Answer
How Do I Center A GUI Label? 5 Answers
Text Alignment 2 Answers