// ---------------------------------------------------------------------------------
        public Vector2 LayoutSizeForObjectInTableView(DSTableView tableView, DSTableColumn tableColumn, int row)
        {
            if (myClassType == null)
            {
                return(Vector2.zero);
            }
            string columnId = tableColumn.Identifier;

            if (string.Compare(columnId, kInColumnId) == 0 || string.Compare(columnId, kOutColumnId) == 0)
            {
                return(myCheckBoxSize);
            }
            VariablePair variablePair      = myVariables[row];
            string       name              = variablePair.DisplayName;
            string       typeName          = variablePair.DisplayTypeName;
            ControlPair  inputControlPair  = variablePair.InputControlPair;
            ControlPair  outputControlPair = variablePair.OutputControlPair;
            GUIStyle     labelStyle        = inputControlPair.IsActive || outputControlPair.IsActive ? EditorStyles.boldLabel : EditorStyles.label;

            if (string.Compare(columnId, kNameColumnId) == 0)
            {
                return(labelStyle.CalcSize(new GUIContent(name)));
            }
            if (string.Compare(columnId, kTypeColumnId) == 0)
            {
                return(labelStyle.CalcSize(new GUIContent(typeName)));
            }
            return(Vector2.zero);
        }
        // ======================================================================
        // Column Methods
        // ----------------------------------------------------------------------
        public DSTableColumn FindTableColumn(string identifier)
        {
            DSTableColumn result = null;

            foreach (var tableColumn in myColumns)
            {
                if (string.Compare(tableColumn.Identifier, identifier) == 0)
                {
                    result = tableColumn;
                    break;
                }
            }
            return(result);
        }
 // ---------------------------------------------------------------------------------
 public void OnMouseDown(DSTableView tableView, DSTableColumn tableColumn, int row)
 {
 }
        // ---------------------------------------------------------------------------------
        public void DisplayObjectInTableView(DSTableView tableView, DSTableColumn tableColumn, int row, Rect position)
        {
            if (myClassType == null)
            {
                return;
            }
            VariablePair variablePair      = myVariables[row];
            string       name              = variablePair.DisplayName;
            string       typeName          = variablePair.DisplayTypeName;
            ControlPair  inputControlPair  = variablePair.InputControlPair;
            ControlPair  outputControlPair = variablePair.OutputControlPair;

            string columnId = tableColumn.Identifier;

            if (string.Compare(columnId, kInColumnId) == 0 && inputControlPair.Component != null)
            {
                if (Math3D.IsEqual(position.height, myCheckBoxSize.y) && Math3D.IsEqual(position.width, myCheckBoxSize.x))
                {
                    bool prevActive = inputControlPair.IsActive;
                    inputControlPair.IsActive = GUI.Toggle(position, inputControlPair.IsActive, "");
                    if (prevActive != inputControlPair.IsActive && myTarget != null && myStorage != null)
                    {
                        if (inputControlPair.IsActive)
                        {
                            iCS_UserCommands.CreatePropertiesWizardElement(myTarget, inputControlPair.Component);
                        }
                        else
                        {
                            iCS_UserCommands.DeletePropertiesWizardElement(myTarget, inputControlPair.Component);
                        }
                    }
                }
            }
            if (string.Compare(columnId, kOutColumnId) == 0 && outputControlPair.Component != null)
            {
                if (Math3D.IsEqual(position.height, myCheckBoxSize.y) && Math3D.IsEqual(position.width, myCheckBoxSize.x))
                {
                    bool prevActive = outputControlPair.IsActive;
                    outputControlPair.IsActive = GUI.Toggle(position, outputControlPair.IsActive, "");
                    if (prevActive != outputControlPair.IsActive && myTarget != null && myStorage != null)
                    {
                        if (outputControlPair.IsActive)
                        {
                            iCS_UserCommands.CreatePropertiesWizardElement(myTarget, outputControlPair.Component);
                        }
                        else
                        {
                            iCS_UserCommands.DeletePropertiesWizardElement(myTarget, outputControlPair.Component);
                        }
                    }
                }
            }
            GUIStyle labelStyle = inputControlPair.IsActive || outputControlPair.IsActive ? EditorStyles.boldLabel : EditorStyles.label;

            if (string.Compare(columnId, kNameColumnId) == 0)
            {
                GUI.Label(position, name, labelStyle);
            }
            if (string.Compare(columnId, kTypeColumnId) == 0)
            {
                GUI.Label(position, typeName, labelStyle);
            }
        }
        public void OnActivate(Type classType, iCS_IStorage storage, GUIContent title = null, iCS_EditorObject target = null)
        {
            // Configuration parameters.
            myClassType = classType;
            myStorage   = storage;
            myTitle     = title ?? new GUIContent(kDefaultTitle);
            myTarget    = target;

            // Common variables.
            myCheckBoxSize = GUI.skin.toggle.CalcSize(new GUIContent(""));

            // Extract fields & properties from class descriptor.
            var libraryDatabase            = LibraryController.LibraryDatabase;
            var libraryType                = libraryDatabase.GetLibraryType(classType);
            var libraryFields              = libraryType.GetMembers <LibraryField>();
            var libraryProperties          = libraryType.GetMembers <LibraryProperty>();
            var libraryFieldsAndProperties = P.append <LibraryObject>(libraryFields, libraryProperties);
            List <VariablePair> variables  = new List <VariablePair>();

            foreach (var libraryObject in libraryFieldsAndProperties)
            {
                bool   isActive     = (myTarget != null && myStorage != null) ? myStorage.PropertiesWizardFindFunction(myTarget, libraryObject) != null : false;
                string name         = GetVariableName(libraryObject);
                var    variablePair = GetVariablePair(name, variables);
                if (libraryObject is LibraryFieldSetter || libraryObject is LibraryPropertySetter)
                {
                    if (variablePair != null)
                    {
                        variablePair.InputControlPair.Component = libraryObject;
                        variablePair.InputControlPair.IsActive  = isActive;
                    }
                    else
                    {
                        variables.Add(new VariablePair(libraryObject, isActive, null, false));
                    }
                }
                else
                {
                    if (variablePair != null)
                    {
                        variablePair.OutputControlPair.Component = libraryObject;
                        variablePair.OutputControlPair.IsActive  = isActive;
                    }
                    else
                    {
                        variables.Add(new VariablePair(null, false, libraryObject, isActive));
                    }
                }
            }
            myVariables = variables.ToArray();
            Array.Sort(myVariables, (x, y) => GetVariableName(x).CompareTo(GetVariableName(y)));

            // Build view
            myTableView            = new DSTableView(new RectOffset(0, 0, 0, 0), true, myTitle, DSView.AnchorEnum.Center, true, true);
            myTableView.DataSource = this;
            DSTableColumn inColumn = new DSTableColumn(kInColumnId, new RectOffset(kSpacer, kSpacer, 0, 0), new GUIContent("In"), DSView.AnchorEnum.Center);

            myTableView.AddColumn(inColumn);
            DSTableColumn outColumn = new DSTableColumn(kOutColumnId, new RectOffset(kSpacer, kSpacer, 0, 0), new GUIContent("Out"), DSView.AnchorEnum.Center);

            myTableView.AddColumn(outColumn);
            DSTableColumn variableNameColumn = new DSTableColumn(kNameColumnId, new RectOffset(kSpacer, kSpacer, 0, 0), new GUIContent("Name"), DSView.AnchorEnum.CenterLeft);

            myTableView.AddColumn(variableNameColumn);
            DSTableColumn variableTypeColumn = new DSTableColumn(kTypeColumnId, new RectOffset(kSpacer, kSpacer, 0, 0), new GUIContent("Type"), DSView.AnchorEnum.CenterLeft);

            myTableView.AddColumn(variableTypeColumn);
        }
        public bool RemoveColumn(DSTableColumn column)
        {
            bool result = myColumns.Remove(column);

            return(result);
        }
 // ======================================================================
 // Column management
 // ----------------------------------------------------------------------
 public void AddColumn(DSTableColumn column)
 {
     myColumns.Add(column);
 }
 public void SetSelection(DSTableColumn column, int row)
 {
     mySelectedColumn = column;
     mySelectedRow    = row;
     myDataSource.OnMouseDown(this, column, row);
 }
        // ======================================================================
        // Handle mouse events.
        // ----------------------------------------------------------------------
        void ProcessMouseEvents(Rect titleArea, Rect dataArea)
        {
            Vector2 mousePosition = Event.current.mousePosition;

            switch (Event.current.type)
            {
            case EventType.ScrollWheel: {
                if (dataArea.Contains(mousePosition))
                {
                    Vector2 delta = 8f * Event.current.delta;
                    if (Math3D.IsZero(myVScrollbarSize))
                    {
                        delta.y = 0;
                    }
                    if (Math3D.IsZero(myHScrollbarSize))
                    {
                        delta.x = 0;
                    }
                    myScrollbarPosition += delta;
                    if (myScrollbarPosition.x < 0)
                    {
                        myScrollbarPosition.x = 0;
                    }
                    if (myScrollbarPosition.y < 0)
                    {
                        myScrollbarPosition.y = 0;
                    }
                    if (myScrollbarPosition.x > myColumnDataSize.x - myHScrollbarSize)
                    {
                        myScrollbarPosition.x = myColumnDataSize.x - myHScrollbarSize;
                    }
                    if (myScrollbarPosition.y > myColumnDataSize.y - myVScrollbarSize)
                    {
                        myScrollbarPosition.y = myColumnDataSize.y - myVScrollbarSize;
                    }
                    Event.current.Use();
                }
                break;
            }

            case EventType.MouseDown: {
                if (dataArea.Contains(mousePosition) || titleArea.Contains(mousePosition))
                {
                    // Determine selected column.
                    float         x = mousePosition.x - titleArea.x + myScrollbarPosition.x;
                    DSTableColumn selectedColumn = null;
                    foreach (var c in myColumns)
                    {
                        selectedColumn = c;
                        float columnWidth = selectedColumn.DataSize.x;
                        if (x < columnWidth)
                        {
                            break;
                        }
                        x -= columnWidth;
                    }
                    // Determine selected row.
                    int selectedRow = -1;
                    if (dataArea.Contains(mousePosition))
                    {
                        float y = mousePosition.y - dataArea.y + myScrollbarPosition.y - 6f;
                        for (int row = 0; row < myRowHeights.Length; ++row)
                        {
                            float rowHeight = myRowHeights[row];
                            if (y < rowHeight)
                            {
                                selectedRow = row;
                                break;
                            }
                            y -= rowHeight;
                        }
                    }
                    if (selectedColumn != mySelectedColumn || selectedRow != mySelectedRow)
                    {
                        mySelectedColumn = selectedColumn;
                        mySelectedRow    = selectedRow;
                        myDataSource.OnMouseDown(this, selectedColumn, selectedRow);
                    }
                    Event.current.Use();
                }
                break;
            }

            case EventType.MouseUp: {
                break;
            }
            }
        }