There’s some way to put a placeholder text(you know, italic in gray) in the string box using custom editor or property drawer?
Here a example of string box photoshoped to look like I want:
There’s some way to put a placeholder text(you know, italic in gray) in the string box using custom editor or property drawer?
Here a example of string box photoshoped to look like I want:
There’s not a nice way to do this out of the box, but you could draw a GUI.Label with a grey/italicized style over the text field when it is empty.
I’ve made note of this feature request.
haha I think about that yesterday before get sleep “maybe I could draw a text over the thex field and use a conditional to show it only when the text field is empty or not selected” xD
Now I only have one dobt left: There’s a way to check when the field is selected or clicked?
Thanks in forward!
Not without reflection. You’ll need to call the internal TextField passing an ID you get yourself from GetControlID. Then use that ID to check EditorGUI.activeEditor.IsEditingControl(id).
Ok, going to try my best on this workaround, thanks for answer!
Here’s how I managed to implement this feature
string PlaceHolderTextField(Rect rect, string input, string controlID, string placeHolder = "Enter Value...")
{
if (Event.current.type != EventType.Layout)
{
GUI.SetNextControlName(controlID);
if (!string.IsNullOrEmpty(input) || GUI.GetNameOfFocusedControl() == controlID)
return GUI.TextField(rect, input);
else
GUI.TextField(rect, placeHolder, greyTextField);
}
return input;
}
Simply make sure the controlID is unique
Note: downside is GUI.TextField doesn’t allow to paste values… and EditorGUI.TextField doesn’t work GUI.SetNextControlName and GUI.GetNameOfFocusedControl functions afak
I think you could do it like this:
//make an italic style textarea for the placeholder
var placeholderTextStyle = new GUIStyle(EditorStyles.textArea);
placeholderTextStyle.fontStyle = FontStyle.Italic;
//Output the real text field
myText = EditorGUI.TextArea(myRect, myText);
//if thats empty output a disabled dummy one
if (string.IsNullOrEmpty(myText))
{
EditorGUI.BeginDisabledGroup(true);
EditorGUI.TextArea(myRect, "Placeholder Text", placeholderTextStyle);
EditorGUI.EndDisabledGroup();
}