Пример #1
0
        void OnPointerDown(PointerDownEvent e)
        {
            if (m_Active)
            {
                e.StopImmediatePropagation();
                return;
            }

            if (CanStartManipulation(e))
            {
                var ve = (e.currentTarget as VisualElement);
                m_Header = ve.GetFirstAncestorOfType <MultiColumnCollectionHeader>();
                preview  = m_Column.collection.resizePreview;

                if (preview)
                {
                    if (m_PreviewElement == null)
                    {
                        m_PreviewElement = new MultiColumnHeaderColumnResizePreview();
                    }

                    VisualElement previewParent = m_Header.GetFirstAncestorOfType <ScrollView>()?.parent ?? m_Header.parent;

                    previewParent.hierarchy.Add(m_PreviewElement);
                }

                columnLayout = m_Header.columnLayout;
                m_Start      = ve.ChangeCoordinatesTo(m_Header, e.localPosition);
                BeginDragResize(m_Start.x);
                m_Active = true;
                target.CaptureMouse();
                e.StopPropagation();
            }
        }
            void Apply(MultiColumnCollectionHeader header)
            {
                int minCount = Math.Min(m_OrderedColumnStates.Count, header.columns.Count);
                int nextValidOrderedIndex = 0;

                for (var orderedIndex = 0; (orderedIndex < m_OrderedColumnStates.Count) && (nextValidOrderedIndex < minCount); orderedIndex++)
                {
                    var columnState = m_OrderedColumnStates[orderedIndex];

                    Column column = null;

                    // Find column by name
                    if (!string.IsNullOrEmpty(columnState.name))
                    {
                        if (header.columns.Contains(columnState.name))
                        {
                            column = header.columns[columnState.name];
                        }
                    }
                    else
                    {
                        if (columnState.index > header.columns.Count - 1)
                        {
                            continue;
                        }

                        column = header.columns[columnState.index];
                        // If the column has a name then we assume it is not the same column anymore
                        if (!string.IsNullOrEmpty(column.name))
                        {
                            column = null;
                        }
                    }

                    if (column == null)
                    {
                        continue;
                    }

                    header.columns.ReorderDisplay(column.displayIndex, nextValidOrderedIndex++);
                    column.visible      = columnState.visible;
                    column.width        = columnState.width;
                    column.desiredWidth = columnState.actualWidth;
                }

                header.sortDescriptions.Clear();
                foreach (var sortDesc in m_SortDescriptions)
                {
                    header.sortDescriptions.Add(sortDesc);
                }
            }
            /// <summary>
            /// Saves the state of the specified header control.
            /// </summary>
            /// <param name="header">The header control of which state will be saved.</param>
            void Save(MultiColumnCollectionHeader header)
            {
                m_SortDescriptions.Clear();
                m_OrderedColumnStates.Clear();

                foreach (var sortDesc in header.sortDescriptions)
                {
                    m_SortDescriptions.Add(sortDesc);
                }

                foreach (var column in header.columns.displayList)
                {
                    var columnState = new ColumnState()
                    {
                        index = column.index, name = column.name, actualWidth = column.desiredWidth, width = column.width.value, visible = column.visible
                    };

                    m_OrderedColumnStates.Add(columnState);
                }
            }