Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved EditorGUI.PrefixLabel gets truncated

Discussion in 'Immediate Mode GUI (IMGUI)' started by ManuelRauber, May 26, 2022.

  1. ManuelRauber

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    115
    Hi!

    I'm currently implementing a custom property drawer for an attribute.

    To create a label previewing an icon, I've added this to my property drawer:

    Code (CSharp):
    1. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    2. {
    3.   EditorGUI.BeginProperty(position, label, property);
    4.  
    5.   var controlId = GUIUtility.GetControlID(FocusType.Passive, position);
    6.   position = EditorGUI.PrefixLabel(position, controlId, new GUIContent(previewIcon),
    7.     new GUIStyle(EditorStyles.label) { fontSize = 46 });
    8.  
    9.   EditorGUI.EndProperty();
    10. }
    11.  
    12. public override float GetPropertyHeight(SerializedProperty property, GUIContent label) => 46;
    As you can see, I return 46 as height for the label and also 46 for the font size. However, the text is truncated even there is more space available:

    upload_2022-5-26_21-19-37.png

    I'd expect that at least it should not be truncated at the bottom.

    What else do I need to do, that the label uses more space to fully show the text?

    Thanks!
     
  2. ManuelRauber

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    115
    Ok, I found it.

    The rect itself had the correct position. However, for the GUIStyle you also need to set the height.

    So instead of doing this:
    Code (CSharp):
    1.  new GUIStyle(EditorStyles.label) { fontSize = 46 }
    It needs to be this here:

    Code (CSharp):
    1.  new GUIStyle(EditorStyles.label) { fontSize = 46, fixedHeight = 46 }