-
-
Save createdbyx/0be5bef4268afb57c429 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Codefarts.Tests | |
{ | |
using UnityEditor; | |
using UnityEngine; | |
public class textareatextwin : EditorWindow | |
{ | |
private string text = string.Empty; | |
public void OnGUI() | |
{ | |
var style = GUI.skin.textArea; | |
// Calling GUILayout.TextField like this allows it to behave like a TextArea | |
this.text = GUILayout.TextField(this.text, 10, GUI.skin.textField, GUILayout.ExpandWidth(true)); | |
// this line fails because the underlying code calls a hidden GUI.DoTextField method that accepts a miltiline argument | |
// but the multiline argument is set to false which causes the GUI.TextArea to behave like a GUI.TextField | |
// and you are not able to press the return key to start a new line | |
this.text = GUI.TextArea(new Rect(0, 40, 100, 100), this.text, 10, style); | |
// not specifying a style works fine but in my case I needed only one text area to use a custom font (Courier New) with a limited | |
// number of characters. | |
this.text = GUI.TextArea(new Rect(110, 40, 100, 100), this.text, 10); | |
} | |
/* | |
// ===========GUI ============ | |
public static string TextArea(Rect position, string text, int maxLength, GUIStyle style) | |
{ | |
GUIContent gUIContent = GUIContent.Temp(text); | |
GUI.DoTextField(position, GUIUtility.GetControlID(FocusType.Keyboard, position), gUIContent, false, maxLength, style); | |
return gUIContent.text; | |
} | |
private static string TextArea(Rect position, GUIContent content, int maxLength, GUIStyle style) | |
{ | |
GUIContent gUIContent = GUIContent.Temp(content.text, content.image); | |
GUI.DoTextField(position, GUIUtility.GetControlID(FocusType.Keyboard, position), gUIContent, false, maxLength, style); | |
return gUIContent.text; | |
} | |
// ========= GUILayout ============== | |
public static string TextField(string text, int maxLength, GUIStyle style, params GUILayoutOption[] options) | |
{ | |
return GUILayout.DoTextField(text, maxLength, true, style, options); | |
} | |
*/ | |
[MenuItem("Test/Test Text Area Style Window")] | |
public static void Display() | |
{ | |
GetWindow<textareatextwin>().Show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment