Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

(SOLVED) Custom Window MaxWidth just a mess

Discussion in 'Editor & General Support' started by Homicide, Mar 2, 2018.

  1. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    638
    Code (CSharp):
    1.  
    2.  
    3.     private void OnGUI()
    4.     {
    5.         EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(124));
    6.         EditorGUILayout.IntField("Map X Length", mapXLength, GUILayout.MaxWidth(120));
    7.         EditorGUILayout.EndHorizontal();
    8.     }
    no matter what i do the integer entry box is way out of the windows site. I have forced a window size of min max, i don't want it being adjusted.

    Why is it falling outside the window like that. Please and ty anyone.
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    Could you please post a screenshot about the problem? I'm not sure I understand the question.
     
    Homicide likes this.
  3. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    638
    upload_2018-3-3_12-46-44.png

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class A3DEditorUtility : EditorWindow {
    5.  
    6.     [MenuItem("A3D Utilities/A3D Generator")]
    7.     static void Init()
    8.     {
    9.         A3DEditorUtility window = (A3DEditorUtility)EditorWindow.GetWindow(typeof(A3DEditorUtility));
    10.         window.maxSize = new Vector2(140, 500);
    11.         window.minSize = new Vector2(140, 499);
    12.      
    13.         window.Show();
    14.     }
    15.  
    16.     public int mapXLength = 0;
    17.  
    18.     private void OnGUI()
    19.     {
    20.         EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(124));
    21.         EditorGUILayout.IntField("Map X Length", mapXLength, GUILayout.MaxWidth(120));
    22.         EditorGUILayout.EndHorizontal();
    23.     }
    24. }
    25.  
    I don't want the window resized, but if i dont leave 1px margin from min to max, the window doesn't draw a border.

    I've tried setting that IntField maxWidth from 20 to 120, doesnt seem to change a thing. It just draws off window no matter what.
     
  4. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    638
    So another unity issue only i have? ugh
     
  5. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    638
    Solved. MaxWidth does NOT set the entire field (text label and integer entry field). It actually only sets whatever is the first entry it handles.

    For eg : if you write :

    Code (CSharp):
    1. GUILayout.IntField("an integer", x,  GUILayout.maxWidth(44));
    The max width only applies to the actual text label and your integer field stretches way out of bounds.

    if you write :

    Code (CSharp):
    1. GUILayout.IntField(x, GUILayout.maxWidth(44));
    Then your integer field is completely scaled as you desired.

    Solution : create individual labels and fields for full control over the way they are displayed.

    for eg :
    Code (CSharp):
    1.         EditorGUILayout.BeginHorizontal();
    2.         EditorGUILayout.LabelField("Max X Length", GUILayout.MaxWidth(44));
    3.         EditorGUILayout.IntField(mapXLength, GUILayout.MaxWidth(44));
    4.         EditorGUILayout.EndHorizontal();
     
    NamelessGames_ and FerdowsurAsif like this.