- Home /
how to make textArea or a textfield uneditable?
I just want it to display text. so it's not modifyable. How could it be done? or is there some better way to display text than text area or text field?
Answer by Mike 3 · Sep 25, 2010 at 10:54 PM
You can use GUI.Label or GUI.Box (if you want a background) instead
If you want to make a textbox uneditable, just don't store the return from the textbox function. It'll only change if you're storing the new value to the variable you're displaying
thank you. I guess I was so out there to test it as fast as I can, that I forgot "ticking" your answer. Thanks
Answer by Jason-King · Apr 03, 2014 at 08:25 PM
Here's another option which provides select/copy abilities...
void ReadOnlyTextField(string label, string text)
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField(label, GUILayout.Width(EditorGUIUtility.labelWidth - 4));
EditorGUILayout.SelectableLabel(text, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
}
EditorGUILayout.EndHorizontal();
}
The selectablelabel or EditorGuILayouts dont use for the ios or android apps? Because, they give an error when we build the app for those platforms.
Answer by shaystibelman · Nov 15, 2012 at 09:41 AM
An even better way of getting the textfield format but leave it uneditable like a lable, is to make a label with a textfield format, like so:
GUI.Label(Rect(x,y,width,height),VariableName,"TextField");
Answer by daivd.ramz · Nov 18, 2012 at 06:16 AM
tihs code is true for you:
GUI.TextField(Rect(x,y,width,height)),text,"TextField");
just don't save return value from GUI.TextField
Answer by isgoed · Nov 25, 2019 at 08:25 AM
I use the following code to have uneditable (but selectable and copyable) text with text-scrollbars:
void ReadOnlyTextField(string text, float Height)
{
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(Height));
{
// Readonly TextArea with working scrollbars
GUILayout.TextArea(text, EditorStyles.textField, GUILayout.ExpandHeight(true));
}
GUILayout.EndScrollView();
}
The GUILayout.ExpandHeight(true) makes the text-scrollbars work.