void OnInnerLayoutUpdate() { if (!_isInitialized) { return; } int baseX = _innerBox.Geometry.X; ERect bound = _scroller.Geometry; int index = 0; foreach (var page in Element.Children) { var nativeView = Platform.GetRenderer(page).NativeView; bound.X = baseX + index * bound.Width; nativeView.Geometry = bound; index++; } _innerBox.MinimumWidth = Element.Children.Count * bound.Width; if (_toolbar.SelectedItem == null) { return; } int currentPage = MultiPage <Page> .GetIndex(_itemToItemPage[_toolbar.SelectedItem]); _scroller.ScrollTo(currentPage, 0, false); }
void ApplyTranslation(EvasMap map, ERect geometry, ref bool changed) { var shiftX = Forms.ConvertToScaledPixel(Element.TranslationX); var shiftY = Forms.ConvertToScaledPixel(Element.TranslationY); // apply translation, i.e. move/shift the object a little if (shiftX != 0 || shiftY != 0) { if (changed) { // special care is taken to apply the translation last Point3D p; for (int i = 0; i < 4; i++) { p = map.GetPointCoordinate(i); p.X += shiftX; p.Y += shiftY; map.SetPointCoordinate(i, p); } } else { // in case when we only need translation, then construct the map in a simpler way geometry.X += shiftX; geometry.Y += shiftY; map.PopulatePoints(geometry, 0); changed = true; } } }
void UpdateFooterPosition() { if (_footer == null) { return; } var position = CollectionView.ParentPosition; if (IsHorizontal) { position.X += (GetScrollCanvasSize().Width - _footerSize.Width); } else { position.Y += (GetScrollCanvasSize().Height - _footerSize.Height); } var bound = new ERect(position.X, position.Y, _footerSize.Width, _footerSize.Height); if (IsHorizontal) { bound.Height = _allocatedSize.Height; } else { bound.Width = _allocatedSize.Width; } _footer.Geometry = bound; }
void InitializeMeasureCache() { _baseItemSize = 0; _scrollCanvasSize = new ESize(0, 0); _last = new ERect(0, 0, 0, 0); if (!_hasUnevenRows) { return; } if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) { return; } int n = CollectionView.Count; _itemSizes = new List <int>(); _cached = new List <bool>(); _accumulatedItemSizes = new List <int>(); 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] : 0) + _itemSizes[i]); } } }
void OnInnerLayoutUpdate() { if (!_isInitalized || (_layoutBound == _innerContainer.Geometry.Size && _childCount == Element.Children.Count)) { return; } _layoutBound = _innerContainer.Geometry.Size; _childCount = Element.Children.Count; int baseX = _innerContainer.Geometry.X; ERect bound = _scroller.Geometry; int index = 0; foreach (var page in Element.Children) { var nativeView = Platform.GetRenderer(page).NativeView; bound.X = baseX + index * bound.Width; nativeView.Geometry = bound; index++; } var widthRequest = _childCount * bound.Width; _innerContainer.MinimumWidth = widthRequest; if (_innerContainer.Geometry.Width == widthRequest && _scroller.HorizontalPageIndex != _pageIndex) { _scroller.ScrollTo(_pageIndex, 0, true); } }
void OnInnerLayoutUpdate() { if (!_isInitalized || _layoutBound == _innerContainer.Geometry.Size) { return; } _layoutBound = _innerContainer.Geometry.Size; int baseX = _innerContainer.Geometry.X; ERect bound = _scroller.Geometry; int index = 0; foreach (var page in Element.Children) { var nativeView = Platform.GetRenderer(page).NativeView; bound.X = baseX + index * bound.Width; nativeView.Geometry = bound; index++; } _innerContainer.MinimumWidth = Element.Children.Count * bound.Width; if (_scroller.HorizontalPageIndex != _pageIndex) { // If you change the orientation of the device and the Animation is set to false, it will not work. _scroller.ScrollTo(_pageIndex, 0, true); } }
void OnInnerLayoutUpdate() { if (_lastLayoutBound == _innerContainer.Geometry) { return; } _lastLayoutBound = _innerContainer.Geometry; var layoutBound = _innerContainer.Geometry.Size; int baseX = _innerContainer.Geometry.X; ERect bound = _scroller.Geometry; int index = 0; foreach (var item in _items) { bound.X = baseX + index * bound.Width; item.Bound = bound; if (item.IsRealized) { item.NativeView.Geometry = bound; } index++; } _innerContainer.MinimumWidth = _items.Count * bound.Width; if (_items.Count > _currentIndex && _currentIndex >= 0 && !_isScrolling) { _updateByCode++; _scroller.ScrollTo(_currentIndex, 0, false); _updateByCode--; } }
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; }
int GetEndIndex(ERect bound) { if (!_hasUnevenRows) { return(GetEndIndex(bound, BaseItemSize)); } return(FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortEndPoint(bound))); }
int GetStartIndex(ERect bound) { if (!_hasUnevenRows) { return(GetStartIndex(bound, BaseItemSize + ItemSpacing)); } return(FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortStartPoint(bound)) * Span); }
int GetEndIndex(ERect bound) { if (!_hasUnevenRows) { return(GetEndIndex(bound, BaseItemSize + ItemSpacing)); } var tmp = FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortEndPoint(bound)); return((FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortEndPoint(bound)) + 1) * Span - 1); }
public void Draw(ERect bound) { X = bound.X; Y = bound.Y; Width = bound.Width; Height = bound.Height; Draw(); // It is workaround for fix geometry issue // A polygon make a margin of 1 pixel at the outermost point Geometry = bound; }
void ApplyScale(EvasMap map, ERect geometry, ref bool changed) { var scale = Element.Scale; // apply scale factor if (scale != 1.0) { map.Zoom(scale, scale, geometry.X + (int)(geometry.Width * Element.AnchorX), geometry.Y + (int)(geometry.Height * Element.AnchorY)); changed = true; } }
void OnLayout() { var outter = Control.Geometry; var width = outter.Width - Forms.ConvertToScaledPixel(Element.Padding.HorizontalThickness); var height = outter.Height - Forms.ConvertToScaledPixel(Element.Padding.VerticalThickness); var left = outter.Left + Forms.ConvertToScaledPixel(Element.Padding.Left); var top = outter.Top + Forms.ConvertToScaledPixel(Element.Padding.Top); var imageBound = new ERect(left, top, width, height); _image.Geometry = imageBound; _button.Geometry = outter; _round.Draw(outter); _border.Draw(outter); }
void ApplyRotation(EvasMap map, ERect geometry, ref bool changed) { var rotationX = Element.RotationX; var rotationY = Element.RotationY; var rotationZ = Element.Rotation; var anchorX = Element.AnchorX; var anchorY = Element.AnchorY; // apply rotations if (rotationX != 0 || rotationY != 0 || rotationZ != 0) { map.Rotate3D(rotationX, rotationY, rotationZ, (int)(geometry.X + geometry.Width * anchorX), (int)(geometry.Y + geometry.Height * anchorY), 0); changed = true; } }
public void SetHeader(EvasObject header, ESize 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(); } var position = CollectionView.ParentPosition; if (_header != null) { var bound = new ERect(position.X, position.Y, _headerSize.Width, _headerSize.Height); if (IsHorizontal) { bound.Height = _allocatedSize.Height; } else { bound.Width = _allocatedSize.Width; } _header.Geometry = bound; } }
static Task AnimatedMove(IAnimatable animatable, EvasObject target, ERect dest, Easing easing = null, uint length = 120) { var tcs = new TaskCompletionSource <bool>(); var dx = target.Geometry.X - dest.X; var dy = target.Geometry.Y - dest.Y; new Animation((progress) => { ERect toMove = dest; toMove.X += (int)(dx * (1 - progress)); toMove.Y += (int)(dy * (1 - progress)); target.Geometry = toMove; }).Commit(animatable, "Move", rate: 60, length: length, easing: easing, finished: (p, e) => { tcs.SetResult(true); }); return(tcs.Task); }
void ApplyRotation(EvasMap map, ERect geometry, ref bool changed) { var rotationX = Element.RotationX; var rotationY = Element.RotationY; var rotationZ = Element.Rotation; var anchorX = Element.AnchorX; var anchorY = Element.AnchorY; // apply rotations if (rotationX != 0 || rotationY != 0 || rotationZ != 0) { map.Rotate3D(rotationX, rotationY, rotationZ, (int)(geometry.X + geometry.Width * anchorX), (int)(geometry.Y + geometry.Height * anchorY), 0); // the last argument is focal length, it determine the strength of distortion. We compared it with the Android implementation map.Perspective3D(geometry.X + geometry.Width / 2, geometry.Y + geometry.Height / 2, 0, (int)(1.3 * Math.Max(geometry.Height, geometry.Width))); // Need to unset clip because perspective 3d rotation is going beyond the container bound NativeView.SetClip(null); changed = true; } }
bool ShouldRearrange(ERect viewport) { if (_isLayouting) { return(false); } if (_last.Size != viewport.Size) { return(true); } var diff = IsHorizontal ? Math.Abs(_last.X - viewport.X) : Math.Abs(_last.Y - viewport.Y); if (diff > BaseItemSize) { return(true); } return(false); }
void UpdateItems() { _items.Clear(); _indexIndicator.Clear(); _innerContainer.UnPackAll(); _lastLayoutBound = default(ERect); foreach (var item in ShellSection.Items) { var indexItem = _indexIndicator.Append(null); indexItem.SetIndexItemStyle(ShellSection.Items.Count, _items.Count, EvenMiddleItem, OddMiddleItem); _items.Add(new ItemHolder { IsRealized = false, IndexItem = indexItem, Item = item }); } _indexIndicator.Update(0); UpdateCurrentPage(ShellSection.Items.IndexOf(ShellSection.CurrentItem)); }
/// <summary> /// Triggers the <c>LayoutUpdated</c> event. /// </summary> /// <remarks> /// This method is called whenever there is a possibility that the size and/or position has been changed. /// </remarks> void NotifyOnLayout() { if (null != LayoutUpdated) { var g = Geometry; if (0 == g.Width || 0 == g.Height || g == _previousGeometry) { // ignore irrelevant dimensions return; } LayoutUpdated(this, new LayoutEventArgs() { Geometry = g, } ); _previousGeometry = g; } }
protected virtual void ApplyTransformation() { if (null == NativeView) { Log.Error("Trying to apply transformation to the non-existent native control"); return; } // prepare the EFL effect structure ERect geometry = NativeView.Geometry; EvasMap map = new EvasMap(4); map.PopulatePoints(geometry, 0); bool changed = false; ApplyRotation(map, geometry, ref changed); ApplyScale(map, geometry, ref changed); ApplyTranslation(map, geometry, ref changed); NativeView.IsMapEnabled = changed; if (changed) { NativeView.EvasMap = map; if (!_movedCallbackEnabled) { _movedCallbackEnabled = true; NativeView.Moved += OnMoved; } } else { if (_movedCallbackEnabled) { _movedCallbackEnabled = false; NativeView.Moved -= OnMoved; } } }
public Task ScrollToAsync(ERect rect, bool animated) { CheckTaskCompletionSource(); ScrollTo(rect, animated); return(animated && _isAnimation ? _animationTaskComplateSource.Task : Task.CompletedTask); }
public static Multimedia.Rectangle ToMultimedia(this ElmSharp.Rect rect) { return(new Multimedia.Rectangle(rect.X, rect.Y, rect.Width, rect.Height)); }
int GetStartIndex(ERect bound, int itemSize) { return(ViewPortStartPoint(bound) / itemSize); }
int ViewPortSize(ERect viewPort) { return(IsHorizontal ? viewPort.Width : viewPort.Height); }
int ViewPortEndPoint(ERect viewPort) { return(ViewPortStartPoint(viewPort) + ViewPortSize(viewPort)); }
int ViewPortStartPoint(ERect viewPort) { return(IsHorizontal ? viewPort.X : viewPort.Y); }
int GetStartIndex(ERect bound, int itemSize) { return((ViewPortStartPoint(bound) - ItemStartPoint) / itemSize * Span); }
int GetEndIndex(ERect bound, int itemSize) { return((int)Math.Ceiling(ViewPortEndPoint(bound) / (double)itemSize) * Span - 1); }