Search Unity

EditorGUI.MultiFloatField and Editor Inspector window width

Discussion in 'Immediate Mode GUI (IMGUI)' started by DSivtsov, Oct 10, 2021.

  1. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    151
    Testing the element EditorGUI.MultiFloatField (can be easy used for creating "standard Transform properties" - Position, Rotation etc.). I detected very specific reaction on changing the Editor Inspector width:
    1. if you set the width of Editor Inspector on possible minimum ("Minimum Mode"), that element begin "draw yourself " in 2 lines (the common label on first line and other part of element on second)
    InspectorWidthMinimum.JPG

    2. If the width of Inspector will be wider ("Common/Normal Mode"), that element begin "draw yourself " in 1 line (the both parts on one line). Note. In these case I had set the "common label" on minimum by special (see below).
    InspectorWidthNormal.JPG

    3. I tried to set different values of width for
    GUILayoutUtility.GetRec() / EditorGUIUtility.labelWidth / EditorGUIUtility.fieldWidth 

    Code (CSharp):
    1.         Rect rect1 = GUILayoutUtility.GetRect(50f, _standartHeight * 2);
    2.         EditorGUIUtility.labelWidth = 10f;
    3.         EditorGUIUtility.fieldWidth = 10f;
    4.         EditorGUI.MultiFloatField(rect1, new GUIContent("EditorGUI.MultiFloatField_1"), new GUIContent[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") }, arrFloat);
    But these values only affect on to draw that element in "Common/Normal Mode" (how the common width will be separated between "Common label" and "Fields"), but doesn't affect on that element in "Minimum Mode", and doesn't affect to the Inspector windows width of when that element are beginning to draw in two lines.

    For me now it's a more an academic question, me interested (I didn't found these information nowhere):
    1. Can be limited the width of Inspector windows which can be set by user?
    2. Does exist the parameters which can forbidden to draw a some element in two lines (this element or others elements)?


    P.S> :)
    I decided to study the GUIStyle's and by random select that element and was upset that the "GUIStule's parameters didn't work" as I had been awaited. :mad::confused::cool:
    But It was a very specific element and all other works fine
     
  2. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Hi, stumbled upon this by chance. What you need is EditorGUIUtility.wideMode. Just set it to true in your editor/drawer when you want those kinds of fields in one line.
     
  3. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    151
    Yes :) You are right. I thought this parameter works as getter only.
    But FYI it have three different state !!! :) (in any case it affect differently on Inspector),
    EditorGUIUtility.wideMode:

    • = true - always in one line
    • = false - always in two line
    • and not set can be one or two lines related to current Inspector width
    Thank you for information.

    Remained another question - Can be limited the width of Inspector windows which can be set by user?
     
  4. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Well, it's never really not set. The Unity editor just sets it before creating each inspector; true if width is bigger than 330, false otherwise. Look: https://github.com/Unity-Technologi...entsEditor/Inspector/InspectorElement.cs#L347

    That means you can actually read
    EditorGUIUtility.wideMode
    to see whether a property drawer of yours should be drawn in one or two lines when you're trying to follow standard Unity Editor practices.