FullInspector.Rotorz.ReorderableList.ReorderableListControl.DrawListItem C# (CSharp) Method

DrawListItem() private method

private DrawListItem ( EventType eventType, Rect position, IReorderableListAdaptor adaptor, int itemIndex ) : void
eventType EventType
position UnityEngine.Rect
adaptor IReorderableListAdaptor
itemIndex int
return void
        private void DrawListItem(EventType eventType, Rect position, IReorderableListAdaptor adaptor, int itemIndex)
        {
            bool visible = true;
            if ((_flags & ReorderableListFlags.DisableClipping) == 0)
                visible = (position.y < _visibleRect.yMax && position.yMax > _visibleRect.y);

            bool draggable = _allowReordering && adaptor.CanDrag(itemIndex);

            Rect itemContentPosition = position;
            itemContentPosition.x = position.x + 2;
            itemContentPosition.y += 1;
            itemContentPosition.width = position.width - 4;
            itemContentPosition.height = position.height - 4;

            // Make space for grab handle?
            if (draggable) {
                itemContentPosition.x += 20;
                itemContentPosition.width -= 20;
            }

            // Make space for element index.
            if (_indexLabelWidth != 0) {
                itemContentPosition.width -= _indexLabelWidth;

                if (eventType == EventType.Repaint && visible)
                    s_RightAlignedLabelStyle.Draw(new Rect(itemContentPosition.x, position.y, _indexLabelWidth, position.height - 4), itemIndex + ":", false, false, false, false);

                itemContentPosition.x += _indexLabelWidth;
            }

            // Make space for remove button?
            if (hasRemoveButtons)
                itemContentPosition.width -= removeButtonStyle.fixedWidth;

            if (eventType == EventType.Repaint && visible) {
                // Draw grab handle?
                if (draggable)
                    GUI.DrawTexture(new Rect(position.x + 6, position.y + position.height / 2f - 3, 9, 5), ReorderableListResources.texGrabHandle);

                // Draw splitter between list items (but not above the first
                // item)
                if (itemIndex != 0 &&
                    (!_tracking || itemIndex != s_AnchorIndex))
                    GUI.DrawTexture(new Rect(position.x, position.y - 1, position.width, 1), ReorderableListResources.texItemSplitter);
            }

            // Allow control to be automatically focused.
            if (s_AutoFocusIndex == itemIndex)
                GUI.SetNextControlName("AutoFocus_" + _controlID + "_" + itemIndex);

            try {
                s_CurrentItemIndex.Push(itemIndex);

                // Present actual control.
                EditorGUI.BeginChangeCheck();
                adaptor.DrawItem(itemContentPosition, itemIndex);
                if (EditorGUI.EndChangeCheck())
                    ReorderableListGUI.indexOfChangedItem = itemIndex;

                // Draw remove button?
                if (hasRemoveButtons && adaptor.CanRemove(itemIndex)) {
                    s_RemoveButtonPosition = position;
                    s_RemoveButtonPosition.width = removeButtonStyle.fixedWidth;
                    s_RemoveButtonPosition.x = itemContentPosition.xMax + 2;
                    s_RemoveButtonPosition.height -= 2;

                    if (DoRemoveButton(s_RemoveButtonPosition, visible))
                        RemoveItem(adaptor, itemIndex);
                }

                // Check for context click?
                if (eventType == EventType.ContextClick && position.Contains(Event.current.mousePosition) && (flags & ReorderableListFlags.DisableContextMenu) == 0) {
                    ShowContextMenu(_controlID, itemIndex, adaptor);
                    Event.current.Use();
                }
            }
            finally {
                s_CurrentItemIndex.Pop();
            }
        }