Question by
aj_lenzie · Mar 18, 2016 at 01:31 AM ·
user interface
What is the offset or space between GUILayout elements?
These don't quite line up because of the space between UI elements. I am curious if anyone happens to know the default space between GUILayout elements.
private Rect _settingsMenuTopBarArea;
private float _screenWidth = Screen.width;
private float _screenHeight = Screen.height;
private float _boxPosX = 0;
private float _boxPosY = Screen.height / 24;
private Rect _selectableButtonArea;
private float _selectableButtonsPosY = Screen.height / 18;
private float _selectableButtonHeight = Screen.height / 18;
private float _xOffset = Screen.width / 24;
private float _yOffset = Screen.height / 24;
public Rect displayArea;
private float _displayAreaPosX = Screen.width / 33;
private float _displayAreaPosY = Screen.height / 4.5f;
private float _displayAreaWidth = Screen.width - (Screen.width / 16);
private float _displayAreaHeight = Screen.height - (Screen.height / 6) * 2;
public GUIStyle myStyle = new GUIStyle ();
public GUIStyle buttonStyle = new GUIStyle ();
public GUIStyle gunsmithStyle = new GUIStyle ();
void Awake () {
_settingsMenuTopBarArea = new Rect (_boxPosX + _xOffset, _boxPosY, _screenWidth - _xOffset * 2, _screenHeight);
_selectableButtonArea = new Rect (_boxPosX, _selectableButtonsPosY + _boxPosY + _yOffset, _screenWidth, _selectableButtonHeight);
displayArea = new Rect (_displayAreaPosX + (_xOffset / 2), _displayAreaPosY, _displayAreaWidth - _xOffset, _displayAreaHeight);
myStyle.fontSize = (int)(Screen.width * 0.03f);
myStyle.normal.textColor = Color.white;
buttonStyle.fontSize = (int)(Screen.width * 0.015f);
buttonStyle.normal.textColor = Color.white;
}
void OnGUI () {
if (MenuManager._settingsMenuOpen) {
GUI.color = new Color (1f, 1f, 1f, .75f);
SettingsMenuTopBar ();
SelectableButtons ();
DisplayIdentityArea ();
GUI.color = new Color (1f, 1f, 1f, 1f);
}
}
void SettingsMenuTopBar () {
GUILayout.BeginArea (_settingsMenuTopBarArea);
GUILayout.BeginHorizontal (GUILayout.ExpandWidth (true), GUILayout.Height (Screen.height / 12));
GUILayout.Box ("MENU", myStyle, GUILayout.Width (Screen.width / 8), GUILayout.Height (Screen.height / 14));
GUILayout.EndHorizontal ();
GUILayout.EndArea ();
}
void SelectableButtons () {
float buttonPadding = 2.5f;
GUILayout.BeginArea (_selectableButtonArea);
GUILayout.BeginHorizontal (GUILayout.Width ((_screenWidth / 1.5f) - _xOffset * 2), GUILayout.Height (_selectableButtonHeight));
GUILayout.Space (_xOffset * 2);
if (GUILayout.Button ("IDENTITY", buttonStyle, GUILayout.ExpandHeight (true))) {
DisplayIdentityArea ();
}
GUILayout.Space (buttonPadding);
if (GUILayout.Button ("CHALLANGES", buttonStyle, GUILayout.ExpandHeight (true))) {
DisplayChallengesArea ();
}
GUILayout.Space (buttonPadding);
if (GUILayout.Button ("BARRACKS", buttonStyle, GUILayout.ExpandHeight (true))) {
DisplayBarracksArea ();
}
GUILayout.Space (buttonPadding);
if (GUILayout.Button ("MEDIA", buttonStyle, GUILayout.ExpandHeight (true))) {
DisplayMediaArea ();
}
GUILayout.Space (buttonPadding);
if (GUILayout.Button ("OPTIONS", buttonStyle, GUILayout.ExpandHeight (true))) {
DisplayOptionsArea ();
}
GUILayout.EndHorizontal ();
GUILayout.EndArea ();
}
void DisplayIdentityArea () {
GUILayout.BeginArea (displayArea);
// GUILayout.Box ("Box", GUILayout.ExpandWidth (true), GUILayout.ExpandHeight (true));
GUILayout.BeginHorizontal (GUILayout.ExpandWidth (true), GUILayout.Height (displayArea.height / 1.6f));
GUILayout.Box ("", GUILayout.Width ((displayArea.width / 3) * 2 + Screen.width / 128), GUILayout.Height (displayArea.height / 1.6f));
GUILayout.BeginVertical ();
GUILayout.Box ("", GUILayout.Width (displayArea.width / 3.1f), GUILayout.Height (displayArea.height / 2.6f));
GUILayout.Box ("", GUILayout.Width (displayArea.width / 3.1f), GUILayout.ExpandHeight (true));
GUILayout.EndVertical ();
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal (GUILayout.ExpandWidth (true), GUILayout.ExpandHeight (true));
GUILayout.Box ("", GUILayout.Width (displayArea.width / 3), GUILayout.ExpandHeight (true));
GUILayout.Box ("", GUILayout.Width (displayArea.width / 3), GUILayout.ExpandHeight (true));
GUILayout.Box ("", GUILayout.Width (displayArea.width / 3.075f), GUILayout.ExpandHeight (true));
GUILayout.EndHorizontal ();
GUILayout.EndArea ();
}
void DisplayChallengesArea () {
}
void DisplayBarracksArea () {
}
void DisplayMediaArea () {
}
void DisplayOptionsArea () {
}
Comment
It appears to be a Screen.width / x since it scales based on screen resolution. Just wondering if anyone knows what x is though!
@16:9 - x appears to be 192. Is there something universal though?
Answer by aj_lenzie · Mar 18, 2016 at 02:20 AM
So after putzing around, everything ended up adjusting itself once I added a GUIStyle. I actually had to go in and add my own GUILayout.Space () to everything. I will update my code once I finish updating it in working condition just in case anyone else runs across this issue.