Search Unity

Label with two texts like in IMGUI LabelField?

Discussion in 'UI Toolkit' started by Xarbrough, Oct 22, 2021.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,112
    I was hoping for a replacement for EditorGUILayout.LabelField("My Text", "Some longer text"). Is there any editor-specific label in UI Toolkit which supports two strings and does the typical inspector layout with two columns? I'm specifically looking for static text, not the UI Toolkit TextField which takes user input.
     
  2. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    149
    Hey! Nothing built-in at this point to do this, but you can achieve this by creating a VisualElement (with
    flex-direction:row
    ) with two Label children.
     
    Xarbrough likes this.
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,112
    Thanks, yea that's something I can use, but I'm mostly concerned with getting the sizes right. In IMGUI, the EditorGUI.labelWidth defined how much space was reserved for labels vs content on the right side. I assume this value is still defined somewhere in UI Toolkit, maybe via some unity style I can use?
     
  4. cpalma-unity

    cpalma-unity

    Unity Technologies

    Joined:
    Nov 30, 2020
    Posts:
    25
    Hello! As @martinpa_unity mentioned we don't have a LabelField control right now, but we would definitely add it in the future since we want to reach parity with IMGUI.

    About aligning custom fields, we are currently working on a few improvements so you can opt-in for the label alignment behavior. Right now, there is no workaround for this other than manually setting your width and min-width according to your inspector element size and nesting level in foldouts and lists.
     
    Xarbrough likes this.
unityunity