Hey folks, I’m trying to do what I think is a pretty simple operation, but it seems like I’m missing some ideas or concepts about how EditorGUIs should be structured.
The idea is very simple, I’m trying to build a custom editor window with a vertically scrolling list of items, but I’m unable to get the scrollview’s area to contain all the items, that is, when I have more items in the scrollview than the window size, I can’t scroll down to see all of them. Here’s my code:
// cScrollSize is actually calculated from the number of elements
int cScrollSize = 800;
// If I set the GUILayout.Height to cScrollSize, THEN I can see all the elements
// but I may have as many as 128 elements, which will be much more than the
// vertical resolution of my monitor, so obviously that's not a solution
mScrollPos = EditorGUILayout.BeginScrollView(mScrollPos, true, true,
new GUILayoutOption[] {
GUILayout.Width(400),
GUILayout.Height(500),
GUILayout.ExpandHeight(true)
});
// Is the vertical layout necessary, or can I add content directly under the scrollview?
mRectLogCtrls = EditorGUILayout.BeginVertical(new GUILayoutOption[] {
GUILayout.Width(800),
GUILayout.Height(cScrollSize)
});
GUI.Label(new Rect(0, 0, 200, 30), "Input Channels");
int start = 20;
int cY = start;
for(int cid=0;cid<mController.InputChannels.Count;++cid)
{
cY = start + (20 * cid);
GUI.Label(new Rect(15, cY, 100, 20),
mController.InputChannels[cid].ChannelName);
GUI.Toggle(new Rect(115, cY, 100, 20),
mController.InputChannels[cid].ChannelActive,
"Active");
GUI.Toggle(new Rect(215, cY, 100, 20),
mController.InputChannels[cid].ChannelManual,
"Manual");
GUI.TextField(new Rect(315, cY, 100, 20),
mController.InputChannels[cid].ChannelAssignment);
}
cY += 20;
GUI.Label(new Rect(0, cY, 200, 30), "Output Channels");
cY += 20;
start = cY;
for (int cid = 0; cid < mController.OutputChannels.Count; ++cid)
{
cY = start + (20 * cid);
GUI.Label(new Rect(15, cY, 100, 20),
mController.OutputChannels[cid].ChannelName);
GUI.Toggle(new Rect(115, cY, 100, 20),
mController.OutputChannels[cid].ChannelActive,
"Active");
GUI.Toggle(new Rect(215, cY, 100, 20),
mController.OutputChannels[cid].ChannelManual,
"Manual");
GUI.TextField(new Rect(315, cY, 100, 20),
mController.OutputChannels[cid].ChannelAssignment);
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndScrollView();
This code gives me the following result:
The only way I can make all the elements in the scrollview accessible is to set the size of the scrollview to the size of the content, but it seems like that defeats the purpose of a scrollview. Am I ordering my other controls correctly, am I missing something, is there something obvious? I apologize if this is a simple questions, I’ve searched different forums and it seems like I’m the only person having this problem. Thanks in advance!
