Utamaru
Utamaru

Reputation: 868

How to change ReorderableList's element height in Inspector view

I created custom inspector for my Journal class to display List<T> as ReorderableList<T>. To display class structure I wrote following code:

private ReorderableList list;

private void OnEnable()
{
            list.drawElementCallback =
            (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                rect = new Rect(rect.x, rect.y, rect.width, rect.height * 2);
                var element = list.serializedProperty.GetArrayElementAtIndex(index);
                rect.y += 2;
                EditorGUI.PropertyField(
                    new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("Name"), GUIContent.none);
                EditorGUI.PropertyField(
                    new Rect(rect.x + 100, rect.y, rect.width - 100, EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("Image"), GUIContent.none);
                EditorGUI.PropertyField(
                    new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight + 2f, rect.width, EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("Description"), GUIContent.none);
            };

I expected it to be displayed like this:

[1: Name] [1: Picture]
[1: Description]
[2: Name] [2: Picture]
[2: Description]

But in result, "Description" of the first element overlapping with "Name" and "Picture" of the second element and so on.

enter image description here

And I can't find any way to increase ReorderableList's element height. Setting rect.min doesn't help

Upvotes: 6

Views: 5662

Answers (1)

Utamaru
Utamaru

Reputation: 868

list.elementHeight = EditorGUIUtility.singleLineHeight * 2f;

Upvotes: 5

Related Questions