Can't figure out how to make a small scrolling box inside an editor window
I'm trying to make my own 'console' of sorts in a custom Editor Window. I want it to work more or less the same as the regular console: messages are rendered inside rects which are stacked vertically inside a larger, scrollable rect, which is embedded in my editor window.
So far this is what I have:
which is created through the following code:
private void ConsoleDrawer()
{
float margin = 20f;
Rect rect = new Rect(margin, 100f + margin, Screen.width - (margin * 2), Screen.height - 200f);
GUILayout.BeginArea(rect, GUI.skin.box);
m_debugConsoleScroll = GUILayout.BeginScrollView(m_debugConsoleScroll, false, true);
GUILayout.BeginVertical();
for (int i = 0; i < 1000; i++)
{
GUILayout.BeginArea(new Rect(-2f, 30f * i - 1f, Screen.width, 30f), GUI.skin.box);
GUILayout.EndArea();
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndArea();
}
This seems quite similar to all the examples I can find elsewhere, but no matter how I order things or what parameters I change, the scroll area never seems to work how I want it to, i.e. grow to accommodate all 1000 smaller rects.
Answer by Adam-Mechtley · Jan 13, 2017 at 10:49 AM
Why are you calling GUILayout.BeginArea
inside of an area you have already created (i.e. the one inside of the ScrollView scope)? If you need a rect in there, you should instead use GUILayoutUtility.GetRect()
, or just directly draw the controls you need (e.g., GUILayout.Label
, GUILayout.Button
).