void InitializeMeasureCache() { _baseItemSize = 0; _scrollCanvasSize = new Size(0, 0); _lastLayoutedBound = new Rect(0, 0, 0, 0); if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) { return; } if (!_hasUnevenRows) { CollectionView !.ContentSizeUpdated(); return; } int n = CollectionView !.Count; _itemSizes = new List <double>(); _cached = new List <bool>(); _accumulatedItemSizes = new List <double>(); for (int i = 0; i < n; i++) { _cached.Add(false); _itemSizes.Add(BaseItemSize); if (i % Span == 0) { int accIndex = i / Span; _accumulatedItemSizes.Add((accIndex > 0 ? (_accumulatedItemSizes[accIndex - 1] + ItemSpacing) : ItemStartPoint) + _itemSizes[i]); } } CollectionView !.ContentSizeUpdated(); }
void UpdateFooterPosition() { if (_footer == null) { return; } var point = new Point(); if (IsHorizontal) { point.X += (GetScrollCanvasSize().Width - _footerSize.Width); } else { point.Y += (GetScrollCanvasSize().Height - _footerSize.Height); } var bound = new Rect(point, _footerSize); if (IsHorizontal) { bound.Height = _allocatedSize.Height; } else { bound.Width = _allocatedSize.Width; } _footer.UpdateBounds(bound); }
int GetEndIndex(Rect bound) { if (!_hasUnevenRows) { return(GetEndIndex(bound, BaseItemSize + ItemSpacing)); } return((FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortEndPoint(bound)) + 1) * Span - 1); }
int GetStartIndex(Rect bound) { if (!_hasUnevenRows) { return(GetStartIndex(bound, BaseItemSize + ItemSpacing)); } return(FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortStartPoint(bound))); }
public static void UpdateBounds(this View view, Rect bounds) { if (view.Size.Width != bounds.Width || view.Size.Height != bounds.Height) { view.Size = bounds.Size.ToNative(); } if (view.Position.X != bounds.X || view.Position.Y != bounds.Y) { view.Position = bounds.Location.ToNative(); } }
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; }
public void SetHeader(View?header, Size size) { bool contentSizeChanged = false; if (IsHorizontal) { if (_headerSize.Width != size.Width) { contentSizeChanged = true; } } else { if (_headerSize.Height != size.Height) { contentSizeChanged = true; } } _header = header; _headerSize = size; if (contentSizeChanged) { InitializeMeasureCache(); CollectionView !.ContentSizeUpdated(); } if (_header != null) { var bound = new Rect(0, 0, _headerSize.Width, _headerSize.Height); if (IsHorizontal) { bound.Height = _allocatedSize.Height; } else { bound.Width = _allocatedSize.Width; } _header.UpdateBounds(bound); } }
bool ShouldRearrange(Rect viewport) { if (_isLayouting) { return(false); } if (_lastLayoutedBound.Size != viewport.Size) { return(true); } var diff = IsHorizontal ? Math.Abs(_lastLayoutedBound.X - viewport.X) : Math.Abs(_lastLayoutedBound.Y - viewport.Y); if (diff > BaseItemSize) { return(true); } return(false); }
public static void UpdateBounds(this View view, Rect bounds) { view.Size = bounds.Size.ToNative(); view.Position = bounds.Location.ToNative(); }
double ViewPortSize(Rect viewPort) { return(IsHorizontal ? viewPort.Width : viewPort.Height); }
double ViewPortEndPoint(Rect viewPort) { return(ViewPortStartPoint(viewPort) + ViewPortSize(viewPort)); }
double ViewPortStartPoint(Rect viewPort) { return(IsHorizontal ? viewPort.X : viewPort.Y); }
int GetEndIndex(Rect bound, double itemSize) { return((int)Math.Ceiling(ViewPortEndPoint(bound) / (double)itemSize) - 1); }
int GetStartIndex(Rect bound, double itemSize) { return((int)((ViewPortStartPoint(bound) - ItemStartPoint) / itemSize)); }
public static void UpdateBounds(this EvasObject view, Rect bounds) { view.Geometry = new ERect((int)bounds.X, (int)bounds.Y, (int)bounds.Width, (int)bounds.Height); }
public static Rect ToDP(this TRect rect) { return(new Rect(ConvertToScaledDP(rect.X), ConvertToScaledDP(rect.Y), ConvertToScaledDP(rect.Width), ConvertToScaledDP(rect.Height))); }