- Home /
How do I add a scrolling input text box in an EditorWindow? (more info added)
How do I add a scrolling input text box in an EditorWindow?
I've been searching for a while, trying to figure out how to make a scrolling text input box for my Unity Addon I'm building. I've had 0 success in finding a solution that works.
In essence, I need to add a scrolling editable text area to my editorwindow to allow the user to input data of unknown length.
I've tried the following, and no luck.
Vector2 ScrollPos;
String ParseData = "";
ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos,GUILayout.Height(100));
EditorGUILayout.TextArea(ParseData,GUILayout.Height(200));
EditorGUILayout.EndScrollView();
This is the structure of the code I've been seeing everywhere; however, it only encases the textarea with a scroll bar, and doesn't add it to the textarea itself. If the TextArea is larger than the scroll height, it can scroll the TextArea; however, it has no effect on the text inside the TextArea. As I add lines of text into the TextArea, when the text passes the end of the TextArea, there is no way to scroll the text up or down to see the rest.
Example Images: This first images shows text loaded into the TextArea and the scroll bar already aligned at the bottom.
When I add a few lines into the TextArea, the text simply gets pushed off the edge of the TextArea, and the scrollbar does nothing to compensate for this. I've determined that the ScrollView is only encompassing the TextArea, and not working with the TextArea.
I need the scrollbar to be able to scroll the TextArea to allow the user to scroll up and down through the text he writes into the TextArea.
Am I doing it wrong, is there supposed to be a different way to do this?
Note to Mods: My original question was rejected due to lack of information; however, after adding more information, I couldn't figure out how to resubmit the question, so I caved and created a new question.
What version of Unity are you using?. Is it viable to switch to 4.6 beta?. If this is the case, the ScrollRect is much more friendly. Check this out: http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-scroll-rect
Based on responses from a different post on a different site, I don't think the new 4.6 GUI elements will work within Unity Editor components. At least, I haven't found anyone to present a way to use the elements inside an EditorWindow.
I have tried to do this before and failed - I came to the conclusion that it is just not supported. I got odd behaviours like the scroll view text selection appearing outside the bounds of my Inspector control. Not reassuring! I gave up and made my text edit box just automatically spawn with about enough lines to hold the text without scrolling, based on the current content. It was a little funky when the text was edited, but passable.
you could break up the gui, if it exceeds a certain length creating a new gui for anything written past the length that fits on the screen then u could toggle between these with ur mouse scroll, u can use String.Length to deter$$anonymous$$e the amount of characters in the text field and if the character exceeds a pre deter$$anonymous$$ed maxAmount spread the information over 2 gui ins$$anonymous$$d of 1. if u need more information let me know. Edit -- forgot to include, the way in which u would break up your text
if(string.Length > 30) {
string.Split (","[0]);
}
this is literally just the code u might need i haven't tested it but it should be applicable to what ur trying to achieve.
Answer by Habib Loew · May 08, 2015 at 10:26 PM
I believe the issue you're running into is that you're setting a fixed height on your TextArea. In order to achieve the behavior that you're after you should either let the TextArea manage its own size (which can look a little funky if it gets shorter than the ScrollView) or simply have it expand to fill the scroll area, like this:
ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos,GUILayout.Height(100));
EditorGUILayout.TextArea(ParseData, GUILayout.ExpandHeight(true));
EditorGUILayout.EndScrollView();
Your answer
Follow this Question
Related Questions
Window Editor - Particle Effect Window Layout 0 Answers
OnGui elements as objects? 2 Answers
Keep equal width for panels in EditorGUILayout.HorizontalScope 0 Answers
Unity Mobile ScrollView? 0 Answers