- Home /
Editor TextArea with Scrollbar not working properly
Hi Guys, i'm trying to have a TextArea
with scrollbar enabled, however, doesn't work properly, my script :
void OnGUI () {
// ...
Rect area = EditorGUILayout.GetControlRect();
area.height = position.height - area.yMin-50;
Rect a = area;
s = EditorGUILayout.BeginScrollView (s,false,true,GUILayout.Height ( area.height) );
a.width -= 20;
a.width /=2;
a.height = EditorGUIUtility.singleLineHeight * ou.Length;
EditorGUI.TextArea (a ,output);
a.x += a.width;
EditorGUI.TextArea (a ,ou);
EditorGUILayout .EndScrollView();
}
this is what happens, the ScrollView
are not scrolling all area control property. it always appear short even when I'm set a very long text. did I miss something?
PS : bonus point if you know how to get Scrollbar
width
Answer by Nighfox · Jan 23, 2018 at 12:10 PM
Add an ExpandHeight
parameter to EditorGUILayout.TextArea
:
scroll = EditorGUILayout.BeginScrollView(scroll);
text = EditorGUILayout.TextArea(text, GUILayout.ExpandHeight(true));
EditorGUILayout.EndScrollView();
Not sure what happened to @WillNode by now, but still might be useful to some who are still finding for a solution.
This is good..Also here is a updated version for those who are looking in future
scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Height(100));
hintIds=EditorGUILayout.TextArea(hintIds, GUILayout.ExpandHeight(true));
EditorGUILayout.EndScrollView();
Source: -https://answers.unity.com/questions/908365/how-do-i-add-a-scrolling-input-text-box-in-an-edit-1.html
Answer by BahamutGundam · Aug 24, 2020 at 02:23 PM
scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Height(100));
hintIds=EditorGUILayout.TextArea(hintIds, GUILayout.ExpandHeight(true));
EditorGUILayout.EndScrollView();
In Unity 2019.4, using the above code won't auto-scroll the scrollbar when we press enter at the end of the TextArea. Similarly, pressing up-arrow and down-arrow won't scroll, which is bad IMO.
So far, the only way that I could find to be able to reproduce the same behavior as TextAreaAttribute is by using reflection.
MethodInfo method = typeof(EditorGUI).GetMethod("ScrollableTextAreaInternal", BindingFlags.Static | BindingFlags.NonPublic);
Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(300));
object[] parameters = new object[] {
rect,
textAreaContent,
scrollPos,
EditorStyles.textArea
};
object methodResult = method.Invoke(null,parameters);
scrollPos = (Vector2) (parameters[2]);
string textAreaContent = methodResult.ToString();