Exemple #1
0
        public void LayoutItems(ERect bound, bool force)
        {
            if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0)
            {
                return;
            }

            // TODO : need to optimization. it was frequently called with similar bound value.
            if (!ShouldRearrange(bound) && !force)
            {
                return;
            }

            _isLayouting = true;
            _last        = bound;

            int padding    = Span;
            int startIndex = Math.Max(GetStartIndex(bound) - padding, 0);
            int endIndex   = Math.Min(GetEndIndex(bound) + padding, CollectionView.Count - 1);

            foreach (var index in _realizedItem.Keys.ToList())
            {
                if (index < startIndex || index > endIndex)
                {
                    CollectionView.UnrealizeView(_realizedItem[index].View);
                    _realizedItem.Remove(index);
                }
            }

            var parent = CollectionView.ParentPosition;

            for (int i = startIndex; i <= endIndex; i++)
            {
                EvasObject itemView = null;
                if (!_realizedItem.ContainsKey(i))
                {
                    var view = CollectionView.RealizeView(i);

                    _realizedItem[i] = new RealizedItem
                    {
                        View  = view,
                        Index = i,
                    };
                    itemView = view;
                }
                else
                {
                    itemView = _realizedItem[i].View;
                }

                var itemBound = GetItemBound(i);
                itemBound.X      += parent.X;
                itemBound.Y      += parent.Y;
                itemView.Geometry = itemBound;
            }
            _isLayouting = false;
        }
        public void LayoutItems(Rect bound, bool force)
        {
            if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0)
            {
                return;
            }

            // TODO : need to optimization. it was frequently called with similar bound value.
            if (!ShouldRearrange(bound) && !force)
            {
                return;
            }

            _isLayouting       = true;
            _lastLayoutedBound = bound;

            int padding    = Span;
            int startIndex = Math.Max(GetStartIndex(bound) - padding * 2, 0);
            int endIndex   = Math.Min(GetEndIndex(bound) + padding * 2, CollectionView !.Count - 1);

            foreach (var index in _realizedItem.Keys.ToList())
            {
                if (index < startIndex || index > endIndex)
                {
                    CollectionView !.UnrealizeView(_realizedItem[index].View);
                    _realizedItem.Remove(index);
                }
            }

            for (int i = startIndex; i <= endIndex; i++)
            {
                View?itemView = null;
                if (!_realizedItem.ContainsKey(i))
                {
                    var view = CollectionView !.RealizeView(i);

                    _realizedItem[i] = new RealizedItem(view, i);
                    itemView         = view;
                }
                else
                {
                    itemView = _realizedItem[i].View;
                }

                var itemBound = GetItemBound(i);
                itemView.UpdateBounds(itemBound);
            }
            _isLayouting = false;
        }