0
\$\begingroup\$

Picture showcasing issue

How can I add word wrap to the editor textarea? I'm trying to mimic the [TextArea] attribute (word wrap, automatically increase height when needed)

For some reason GUILayout.TextArea() works fine, but EditorGUILayout.TextArea() doesn't have any word wrap. Here's my code:

obj.edibleFlavorText = EditorGUILayout.TextArea(obj.edibleFlavorText, GUILayout.MinHeight(textAreaHeight));

I've tried:

  • Adding GUILayout.ExpandHeight(true) to its options

  • Adding GUI.skin.textArea.wordWrap = true to the start of my editor script

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

In essence, You need to make sure that the style that is used has wordwrap set to true.

The problem with what you tried is that the style you edited isn't used by the TextArea.

Which style is used is actually a weird one, as I expected EditorStyles.textArea but for some reason, unity uses EditorStyles.textField as the default style instead...(which has wordwrap set to false).

So to fix it, just force it to use the correct style :p

EditorGUILayout.TextArea(obj.edibleFlavorText, EditorStyles.textArea);

On a side note, If you need to alter a style for one field, I wouldn't advise to change the built in GUI styles as doing that will change the style for ALL components that use that style (unless that is what you're after).

Instead, I would advise to create a copy of an existing style, modify it and use it for the component you want to edit.

So for example

        GUIStyle myStyle = new GUIStyle(EditorStyles.textField);
        myStyle.wordWrap = true;
        value = EditorGUILayout.TextArea(value, myStyle);
\$\endgroup\$
1
  • \$\begingroup\$ That's bizarre! No wonder Unity is switching to UI Elements, the more I use Unity's IMGUI, the more I'm just blown away by how messy it actually is. Thank you. \$\endgroup\$
    – Pop Car
    Sep 7, 2020 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .