2

Picture showing lack of word wrap in textarea

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)

I know that GUILayout.TextArea() works but I was hoping to use EditorGUILayout because according to the docs it correctly responds to copy/pasting, select all, etc.

My code:

obj.talkableFlavorText = EditorGUILayout.TextArea(obj.talkableFlavorText, GUILayout.MinHeight(textAreaHeight));
Pop Car
  • 363
  • 5
  • 15
  • You only have a single long "word". Where should it wrap? Did you try with more regular text? – Jongware Sep 06 '20 at 12:22
  • Its assigned GUIStyle has a property [word-wrap](https://docs.unity3d.com/ScriptReference/GUIStyle-wordWrap.html) – have you tested that? – Jongware Sep 06 '20 at 12:26
  • Maybe that was a bad example, it still doesn't wrap even with normal words, it just keeps going right. I've now tried GUI.skin.textArea.wordWrap = true but I still get the same result. – Pop Car Sep 06 '20 at 13:01

1 Answers1

5

Use a GUIStyle and set the wordWrap property to true.

Complete example based on Unity Editor Window Example

using UnityEngine;
using UnityEditor;

public class MyWindow : EditorWindow
{
    string myString = "Hello World";

    // Add menu named "My Window" to the Window menu
    [MenuItem("Window/My Window")]
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow));
        window.Show();
    }

    void OnGUI()
    {
        GUIStyle style = new GUIStyle(EditorStyles.textArea);
        style.wordWrap = true;
        myString = EditorGUILayout.TextArea(myString, style);
    }
}

Result:

enter image description here

Russopotomus
  • 595
  • 3
  • 8