Ejemplo n.º 1
0
        public ERect GetItemBound(int index)
        {
            int itemSize   = 0;
            int startPoint = 0;

            if (!_hasUnevenRows)
            {
                itemSize   = BaseItemSize;
                startPoint = ItemStartPoint + (itemSize + ItemSpacing) * index;
            }
            else if (index >= _itemSizes.Count)
            {
                return(new ERect(0, 0, 0, 0));
            }
            else if (_cached[index])
            {
                itemSize   = _itemSizes[index];
                startPoint = _accumulatedItemSizes[index] - itemSize;
            }
            else
            {
                var measured = CollectionView.GetItemSize(index, ItemWidthConstraint, ItemHeightConstraint);
                itemSize = IsHorizontal ? measured.Width : measured.Height;

                if (itemSize != _itemSizes[index])
                {
                    UpdateAccumulatedItemSize(index, itemSize - _itemSizes[index]);
                    _itemSizes[index] = itemSize;

                    CollectionView.ContentSizeUpdated();
                }
                startPoint     = _accumulatedItemSizes[index] - itemSize;
                _cached[index] = true;
            }

            return(IsHorizontal ?
                   new ERect(startPoint, 0, itemSize, _allocatedSize.Height) :
                   new ERect(0, startPoint, _allocatedSize.Width, itemSize));
        }
Ejemplo n.º 2
0
        public ERect GetItemBound(int index)
        {
            int rowIndex    = index / Span;
            int columnIndex = index % Span;
            var columnSize  = ColumnSize;

            int rowStartPoint    = 0;
            int columnStartPoint = 0;
            int itemSize         = 0;

            if (!_hasUnevenRows)
            {
                itemSize         = BaseItemSize;
                rowStartPoint    = ItemStartPoint + rowIndex * (BaseItemSize + ItemSpacing);
                columnStartPoint = columnIndex * (columnSize + ColumnSpacing);
            }
            else if (_cached[index])
            {
                var updatedMaxItemSize = GetMaxItemSize(index);
                itemSize         = _itemSizes[index];
                rowStartPoint    = _accumulatedItemSizes[rowIndex] - updatedMaxItemSize + (updatedMaxItemSize - itemSize) / 2;
                columnStartPoint = columnIndex * (columnSize + ColumnSpacing);
            }
            else
            {
                var oldMaxItemSize = GetMaxItemSize(index);

                var measured = CollectionView.GetItemSize(index, ItemWidthConstraint, ItemHeightConstraint);
                itemSize = IsHorizontal ? measured.Width : measured.Height;

                if (itemSize != _itemSizes[index])
                {
                    _itemSizes[index] = itemSize;
                }

                var updatedMaxItemSize = GetMaxItemSize(index);
                if (oldMaxItemSize != updatedMaxItemSize)
                {
                    UpdateAccumulatedItemSize(rowIndex, updatedMaxItemSize - oldMaxItemSize);
                    int columnStart = (index / Span) * Span;
                    for (int toUpdate = columnStart; toUpdate < index; toUpdate++)
                    {
                        if (_realizedItem.ContainsKey(toUpdate))
                        {
                            var updated = _realizedItem[toUpdate].View.Geometry;
                            if (IsHorizontal)
                            {
                                updated.X += (updatedMaxItemSize - oldMaxItemSize) / 2;
                            }
                            else
                            {
                                updated.Y += (updatedMaxItemSize - oldMaxItemSize) / 2;
                            }
                            _realizedItem[toUpdate].View.Geometry = updated;
                        }
                    }
                    CollectionView.ContentSizeUpdated();
                }
                rowStartPoint    = _accumulatedItemSizes[rowIndex] - updatedMaxItemSize + (updatedMaxItemSize - itemSize) / 2;
                columnStartPoint = columnIndex * (columnSize + ColumnSpacing);

                _cached[index] = true;
            }

            return(IsHorizontal ?
                   new ERect(rowStartPoint, columnStartPoint, itemSize, columnSize) :
                   new ERect(columnStartPoint, rowStartPoint, columnSize, itemSize));
        }