Esempio n. 1
0
        public IReadOnlyList <float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
        {
            if (scroll == null)
            {
                return(new List <float>());
            }
            int lastCount = snapPoints.Count;

            snapPoints.Clear();
            snapPoints.Add(0);
            float snapPoint = 0;

            for (int i = 1; i < rowCount; i++)
            {
                snapPoint = (float)(i * (itemHeight + Space) + Margin.Top - 0.5 * Space);
                if (snapPoint >= scroll.ScrollableHeight)
                {
                    snapPoint = (float)scroll.ScrollableHeight;
                    snapPoints.Add(snapPoint);
                    break;
                }
                else
                {
                    snapPoints.Add(snapPoint);
                }
            }
            if (snapPoint != scroll.ScrollableHeight)
            {
                snapPoints.Add((float)scroll.ScrollableHeight);
            }
            return(snapPoints);
        }
Esempio n. 2
0
        public static CGPoint AdjustContentOffset(CGPoint proposedContentOffset, CGRect itemFrame,
                                                  CGRect viewport, SnapPointsAlignment alignment, UICollectionViewScrollDirection scrollDirection)
        {
            var offset = GetViewportOffset(itemFrame, viewport, alignment, scrollDirection);

            return(new CGPoint(proposedContentOffset.X - offset.X, proposedContentOffset.Y - offset.Y));
        }
Esempio n. 3
0
 public IReadOnlyList <float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     if (orientation != ScrollOrientation)
     {
         return(null);
     }
     return(GetSnapPointsInner(alignment).Distinct().OrderBy(f => f).ToList().AsReadOnly());
 }
 public IReadOnlyList <float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     // NOTE: This method should never be called, both
     // horizontal and vertical SnapPoints are ALWAYS regular.
     //UNREFERENCED_PARAMETER(orientation);
     //UNREFERENCED_PARAMETER(alignment);
     //UNREFERENCED_PARAMETER(returnValue);
     //return E_NOTIMPL;
     throw new NotImplementedException();
 }
Esempio n. 5
0
        //protected override Size ArrangeOverride(Size finalSize)
        //{
        //    HorizontalSnapPointsChanged?.Invoke(this, new object());

        //    return base.ArrangeOverride(finalSize);
        //}

        public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
        {
            offset = 0;

            if (orientation == Orientation.Horizontal && alignment == SnapPointsAlignment.Near)
            {
                return(SnapPointWidth);
            }

            return(0);
        }
        /// <summary>
        /// The distance between the equidistant snap points. Returns 0 when no snap points are present.
        /// </summary>
        /// <param name="orientation">The orientation/dimension for the desired snap point set.</param>
        /// <param name="alignment">The alignment to use when applying the snap points.</param>
        /// <param name="offset">Out parameter. The offset of the first snap point.</param>
        /// <returns>The distance between the equidistant snap points. Returns 0 when no snap points are present.</returns>
        public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
        {
            // Vertical doesn't have snap points
            if (orientation == Orientation.Vertical)
            {
                offset = 0;
                return(0);
            }

            offset = 0;
            return((float)(ColumnWidth + ColumnSpacing));
        }
Esempio n. 7
0
 public IReadOnlyList<float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     if (orientation == Orientation.Vertical)
     {
         var l = new List<float>();
         l.Add((float)this.Children[0].DesiredSize.Height);
         return l;
     }
     else
     {
         return new List<float>();
     }
 }
Esempio n. 8
0
 public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
 {
     if (orientation == Orientation.Horizontal)
     {
         offset = (float)Margin.Left;
         return((float)ColumnWidth * ColumnsPerPage);
     }
     else
     {
         offset = (float)Margin.Top;
         return((float)ColumnHeight * ColumnsPerPage);
     }
 }
        public IReadOnlyList <float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
        {
            if (orientation == Orientation.Vertical)
            {
                return(new List <float>());
            }

            var result = (alignment switch
            {
                SnapPointsAlignment.Near => near(),
                SnapPointsAlignment.Center => center(),
                SnapPointsAlignment.Far => far(),
                _ => Enumerable.Empty <float>(), //TODO
            }).Distinct().OrderBy(x => x).ToList();
Esempio n. 10
0
        WSnapPointsAlignment GetWindowsSnapPointsAlignment(SnapPointsAlignment snapPointsAlignment)
        {
            switch (snapPointsAlignment)
            {
            case SnapPointsAlignment.Center:
                return(WSnapPointsAlignment.Center);

            case SnapPointsAlignment.End:
                return(WSnapPointsAlignment.Far);

            case SnapPointsAlignment.Start:
                return(WSnapPointsAlignment.Near);
            }

            return(WSnapPointsAlignment.Center);
        }
Esempio n. 11
0
        static nfloat FindAlignmentTarget(SnapPointsAlignment snapPointsAlignment, nfloat start, nfloat startInset,
                                          nfloat end, nfloat endInset)
        {
            switch (snapPointsAlignment)
            {
            case SnapPointsAlignment.Center:
                var viewPortStart = start + startInset;
                var viewPortEnd   = end - endInset;
                var viewPortSize  = viewPortEnd - viewPortStart;

                return(viewPortStart + (viewPortSize / 2));

            case SnapPointsAlignment.End:
                return(end - endInset);

            case SnapPointsAlignment.Start:
            default:
                return(start + startInset);
            }
        }
        public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
        {
            // For now the LoopingSelectorPanel will simply return a evenly spaced grid,
            // the vertical and horizontal snap points will be identical.
            //UNREFERENCED_PARAMETER(orientation);
            //UNREFERENCED_PARAMETER(alignment);

            //if (offset == null) throw new ArgumentNullException();
            //if (returnValue == null) throw new ArgumentNullException();

            if (orientation != Orientation.Vertical)
            {
                throw new InvalidOperationException();
            }

            offset = _snapPointOffset;
            var returnValue = _snapPointSpacing;

            return(returnValue);
        }
Esempio n. 13
0
        protected virtual SnapHelper CreateSnapHelper(SnapPointsType snapPointsType, SnapPointsAlignment alignment)
        {
            if (snapPointsType == SnapPointsType.Mandatory)
            {
                switch (alignment)
                {
                case SnapPointsAlignment.Start:
                    return(new StartSnapHelper());

                case SnapPointsAlignment.Center:
                    return(new CenterSnapHelper());

                case SnapPointsAlignment.End:
                    return(new EndSnapHelper());

                default:
                    throw new ArgumentOutOfRangeException(nameof(alignment), alignment, null);
                }
            }

            if (snapPointsType == SnapPointsType.MandatorySingle)
            {
                switch (alignment)
                {
                case SnapPointsAlignment.Start:
                    return(new StartSingleSnapHelper());

                case SnapPointsAlignment.Center:
                    return(new SingleSnapHelper());

                case SnapPointsAlignment.End:
                    return(new EndSingleSnapHelper());

                default:
                    throw new ArgumentOutOfRangeException(nameof(alignment), alignment, null);
                }
            }

            // Use center snapping as the default
            return(new CenterSnapHelper());
        }
Esempio n. 14
0
        public static CGPoint FindAlignmentTarget(SnapPointsAlignment snapPointsAlignment,
                                                  CGPoint contentOffset, UICollectionView collectionView, UICollectionViewScrollDirection scrollDirection)
        {
            var inset  = collectionView.ContentInset;
            var bounds = collectionView.Bounds;

            switch (scrollDirection)
            {
            case UICollectionViewScrollDirection.Vertical:
                var y = FindAlignmentTarget(snapPointsAlignment, contentOffset.Y, inset.Top,
                                            contentOffset.Y + bounds.Height, inset.Bottom);
                return(new CGPoint(contentOffset.X, y));

            case UICollectionViewScrollDirection.Horizontal:
                var x = FindAlignmentTarget(snapPointsAlignment, contentOffset.X, inset.Left,
                                            contentOffset.X + bounds.Width, inset.Right);
                return(new CGPoint(x, contentOffset.Y));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 15
0
        CGPoint ScrollSingle(SnapPointsAlignment alignment, CGPoint proposedContentOffset, CGPoint scrollingVelocity)
        {
            // Get the viewport of the UICollectionView at the current content offset
            var contentOffset = CollectionView.ContentOffset;
            var viewport      = new CGRect(contentOffset, CollectionView.Bounds.Size);

            // Find the spot in the viewport we're trying to align with
            var alignmentTarget = SnapHelpers.FindAlignmentTarget(alignment, contentOffset, CollectionView, ScrollDirection);

            var visibleElements = LayoutAttributesForElementsInRect(viewport);

            // Find the current aligned item
            var currentItem = SnapHelpers.FindBestSnapCandidate(visibleElements, viewport, alignmentTarget);

            if (currentItem == null)
            {
                // Somehow we don't currently have an item in the viewport near the target; fall back to the
                // default behavior
                return(base.TargetContentOffset(proposedContentOffset, scrollingVelocity));
            }

            // Determine the index of the current item
            var currentIndex = visibleElements.IndexOf(currentItem);

            // Figure out the step size when jumping to the "next" element
            var span = 1;

            if (_itemsLayout is GridItemsLayout gridItemsLayout)
            {
                span = gridItemsLayout.Span;
            }

            // Find the next item in the
            currentItem = SnapHelpers.FindNextItem(visibleElements, ScrollDirection, span, scrollingVelocity, currentIndex);

            return(SnapHelpers.AdjustContentOffset(CollectionView.ContentOffset, currentItem.Frame, viewport, alignment,
                                                   ScrollDirection));
        }
Esempio n. 16
0
        static CGPoint GetViewportOffset(CGRect itemFrame, CGRect viewport, SnapPointsAlignment snapPointsAlignment,
                                         UICollectionViewScrollDirection scrollDirection)
        {
            if (scrollDirection == UICollectionViewScrollDirection.Horizontal)
            {
                if (snapPointsAlignment == SnapPointsAlignment.Start)
                {
                    return(new CGPoint(viewport.Left - itemFrame.Left, 0));
                }

                if (snapPointsAlignment == SnapPointsAlignment.End)
                {
                    return(new CGPoint(viewport.Right - itemFrame.Right, 0));
                }

                var centerViewport = Center(viewport);
                var centerItem     = Center(itemFrame);

                return(new CGPoint(centerViewport.X - centerItem.X, 0));
            }

            if (snapPointsAlignment == SnapPointsAlignment.Start)
            {
                return(new CGPoint(0, viewport.Top - itemFrame.Top));
            }

            if (snapPointsAlignment == SnapPointsAlignment.End)
            {
                return(new CGPoint(0, viewport.Bottom - itemFrame.Bottom));
            }

            var centerViewport1 = Center(viewport);
            var centerItem1     = Center(itemFrame);

            return(new CGPoint(0, centerViewport1.Y - centerItem1.Y));
        }
 public IReadOnlyList <float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     throw new NotImplementedException();
 }
Esempio n. 18
0
        private IReadOnlyList <float> CopyMotionSnapPoints(
            bool isForZoomSnapPoints,
            IReadOnlyList <float> snapPoints,
            SnapPointsAlignment alignment,
            double viewportDimension,
            double extentDimension,
            float zoomFactor,
            float staticZoomFactor)
        {
            global::System.Diagnostics.Debug.Assert(staticZoomFactor == 1f || staticZoomFactor == zoomFactor);

            var result = new List <float>(snapPoints.Count);

            if (snapPoints.Count > 0)
            {
                foreach (var sp in snapPoints)
                {
                    var snapPoint = sp;

                    if (isForZoomSnapPoints)
                    {
                        result.Add(snapPoint * staticZoomFactor);
                    }
                    else
                    {
                        // When snap points alignment is Center or Far, the irregular snap points need
                        // to be adjusted based on the static or manipulatable zoom factor. In the Near case
                        // it doesn't matter so do it for consistency.
                        snapPoint *= zoomFactor;

                        var alignedSnapPoint = alignment switch
                        {
                            SnapPointsAlignment.Near => snapPoint,
                            SnapPointsAlignment.Center => (float)(snapPoint - viewportDimension / 2),
                            SnapPointsAlignment.Far => (float)(snapPoint - viewportDimension),
                            _ => throw new IndexOutOfRangeException("alignment")
                        };

                        var distanceFromFarEdge = (float)(extentDimension - viewportDimension - alignedSnapPoint);

                        // With certain scale factors and resolutions the snap points sometimes get pushed out of bounds
                        // by rounding errors, in these cases we need to intervene and return them to the boundary.
                        if (distanceFromFarEdge < 0 &&
                            distanceFromFarEdge >= (-1.0 * (ScrollViewerSnapPointLocationTolerance * Math.Max(1.0f, zoomFactor))))
                        {
                            alignedSnapPoint    = (float)(extentDimension - viewportDimension);
                            distanceFromFarEdge = 0;
                        }
                        if (alignedSnapPoint >= 0 && distanceFromFarEdge >= 0)
                        {
                            if (staticZoomFactor == 1.0f)
                            {
                                alignedSnapPoint /= zoomFactor;
                            }
                            result.Add(alignedSnapPoint);
                        }
                    }
                }
            }

            return(result);
        }
    }
Esempio n. 19
0
 public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
 {
     return(((IScrollSnapPointsInfo)NativeLayout).GetRegularSnapPoints(orientation, alignment, out offset));
 }
Esempio n. 20
0
 IReadOnlyList <float> IScrollSnapPointsInfo.GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     if (SnapPoints == null)
     {
         return(new List <float>());
     }
     return(SnapPoints);
 }
Esempio n. 21
0
 public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
 {
     throw new NotImplementedException();
 }
Esempio n. 22
0
 IReadOnlyList<float> IScrollSnapPointsInfo.GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     if (SnapPoints == null) return new List<float>();
     return SnapPoints;
 }
Esempio n. 23
0
        public async static Task ScrollToItem(this ListViewBase listViewBase, object item, SnapPointsAlignment alignment, bool highlight, double?pixel = null)
        {
            // get the ScrollViewer withtin the ListView/GridView
            var scrollViewer = listViewBase.GetScrollViewer();
            // get the SelectorItem to scroll to
            var selectorItem = listViewBase.ContainerFromItem(item) as SelectorItem;

            // when it's null, means virtualization is on and the item hasn't been realized yet
            if (selectorItem == null)
            {
                // call task-based ScrollIntoViewAsync to realize the item
                await listViewBase.ScrollIntoViewAsync(item);

                // this time the item shouldn't be null again
                selectorItem = (SelectorItem)listViewBase.ContainerFromItem(item);
            }

            if (selectorItem == null)
            {
                return;
            }

            // calculate the position object in order to know how much to scroll to
            var transform = selectorItem.TransformToVisual((UIElement)scrollViewer.Content);
            var position  = transform.TransformPoint(new Point(0, 0));

            if (alignment == SnapPointsAlignment.Near)
            {
                if (pixel is double adjust)
                {
                    position.Y -= adjust;
                }
            }
            else if (alignment == SnapPointsAlignment.Center)
            {
                position.Y -= (listViewBase.ActualHeight - selectorItem.ActualHeight) / 2d;
            }
            else if (alignment == SnapPointsAlignment.Far)
            {
                position.Y -= listViewBase.ActualHeight - selectorItem.ActualHeight;

                if (pixel is double adjust)
                {
                    position.Y += adjust;
                }
            }

            // scroll to desired position with animation!
            scrollViewer.ChangeView(position.X, position.Y, null, alignment != SnapPointsAlignment.Center);

            if (highlight)
            {
                var bubble = selectorItem.Descendants <MessageBubble>().FirstOrDefault() as MessageBubble;
                if (bubble == null)
                {
                    return;
                }

                bubble.Highlight();
            }
        }
Esempio n. 24
0
        private void GetScrollSnapPoints(
            bool isForHorizontalSnapPoints,
            SnapPointsType snapPointsType,
            float zoomFactor,
            float staticZoomFactor,
            double targetExtentDimension,
            double viewportDimension,
            out bool areSnapPointsOptional,
            out bool areSnapPointsSingle,
            out bool areSnapPointsRegular,
            out float regularOffset,
            out float regularInterval,
            out IReadOnlyList <float> resultSnapPoints)
        {
            var shouldProcessSnapPoint    = false;
            SnapPointsAlignment alignment = default;
            float offset   = 0;
            float interval = 0;
            IReadOnlyList <float> irregularSnapPoints = default;

            areSnapPointsOptional = default;
            areSnapPointsSingle   = default;
            regularOffset         = default;
            regularInterval       = default;
            resultSnapPoints      = default;

            if (isForHorizontalSnapPoints)
            {
                if (snapPointsType != SnapPointsType.None)
                {
                    alignment            = HorizontalSnapPointsAlignment;
                    areSnapPointsRegular = _snapPointsInfo.AreHorizontalSnapPointsRegular;
                    if (areSnapPointsRegular)
                    {
                        interval            = _snapPointsInfo.GetRegularSnapPoints(Orientation.Horizontal, alignment, out offset);
                        irregularSnapPoints = null;
                    }
                    else
                    {
                        if (targetExtentDimension < 0)
                        {
                            // TODO
                        }

                        // TODO: cache this call
                        irregularSnapPoints = _snapPointsInfo.GetIrregularSnapPoints(Orientation.Horizontal, alignment);
                        regularInterval     = 0;
                        regularOffset       = 0;
                    }

                    shouldProcessSnapPoint = true;
                }
                else
                {
                    areSnapPointsRegular = false;
                }
            }
            else
            {
                if (snapPointsType != SnapPointsType.None)
                {
                    alignment            = VerticalSnapPointsAlignment;
                    areSnapPointsRegular = _snapPointsInfo.AreVerticalSnapPointsRegular;
                    if (areSnapPointsRegular)
                    {
                        interval            = _snapPointsInfo.GetRegularSnapPoints(Orientation.Vertical, alignment, out offset);
                        irregularSnapPoints = null;
                    }
                    else
                    {
                        if (targetExtentDimension < 0)
                        {
                            // TODO
                        }

                        // TODO: cache this call
                        irregularSnapPoints = _snapPointsInfo.GetIrregularSnapPoints(Orientation.Vertical, alignment);
                        regularInterval     = 0;
                        regularOffset       = 0;
                    }

                    shouldProcessSnapPoint = true;
                }
                else
                {
                    areSnapPointsRegular = false;
                }
            }

            if (shouldProcessSnapPoint)
            {
                if (areSnapPointsRegular)
                {
                    switch (alignment)
                    {
                    case SnapPointsAlignment.Near:
                        regularOffset = offset * staticZoomFactor;
                        break;

                    case SnapPointsAlignment.Center:
                        // When snap points alignment is Center, the snap points need to align
                        // with the center of the viewport. Adjust the offset accordingly.
                        // Both static and manipulatable zoom factors need to be taken into account.
                        if (interval <= 0f)
                        {
                            // Do not handle negative interval in this case
                            interval = 0f;
                        }
                        else
                        {
                            if (viewportDimension >= interval * zoomFactor)
                            {
                                offset *= zoomFactor;
                                offset -= (float)(viewportDimension / 2f);
                                if (staticZoomFactor == 1f)
                                {
                                    offset /= zoomFactor;
                                }

                                while (offset < 0)
                                {
                                    offset += interval * staticZoomFactor;
                                }
                            }
                            else
                            {
                                offset -= (float)(viewportDimension / (2f * zoomFactor));
                                offset *= staticZoomFactor;
                            }

                            regularOffset = offset;
                        }

                        break;

                    case SnapPointsAlignment.Far:
                        regularOffset = offset * staticZoomFactor;
                        break;
                    }

                    regularInterval      = interval * staticZoomFactor;
                    areSnapPointsRegular = true;
                }
                else
                {
                    areSnapPointsRegular = false;

                    resultSnapPoints = CopyMotionSnapPoints(
                        false,
                        irregularSnapPoints,
                        alignment,
                        viewportDimension,
                        targetExtentDimension,
                        zoomFactor,
                        staticZoomFactor);
                }

                areSnapPointsOptional =
                    snapPointsType == SnapPointsType.Optional ||
                    snapPointsType == SnapPointsType.OptionalSingle;
            }
        }
Esempio n. 25
0
 IReadOnlyList <float> IScrollSnapPointsInfo.GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     if (orientation == Orientation.Vertical)
     {
         var l = new List <float>();
         l.Add((float)this.Children[0].DesiredSize.Height);
         return(l);
     }
     else
     {
         return(new List <float>());
     }
 }
Esempio n. 26
0
 public static T SnapPointsAlignment <T>(this T element, SnapPointsAlignment alignment) where T : ItemsLayout
 {
     element.SnapPointsAlignment = alignment;
     return(element);
 }
Esempio n. 27
0
 public IReadOnlyList <float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     return(((IScrollSnapPointsInfo)NativeLayout).GetIrregularSnapPoints(orientation, alignment));
 }
 public IReadOnlyList<float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     throw new NotImplementedException();
 }
 public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
 {
     if (orientation == Orientation.Horizontal)
     {
         offset = (float)Margin.Left;
         return (float)ColumnWidth * ColumnsPerPage;
     }
     else
     {
         offset = (float)Margin.Top;
         return (float)ColumnHeight * ColumnsPerPage;
     }
 }
Esempio n. 30
0
 float IScrollSnapPointsInfo.GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
 {
     throw new NotImplementedException();
 }
 public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
 {
     offset = (float)this.loopingSelector.ItemOffset;
     return(this.loopingSelector.ItemHeight);
 }
Esempio n. 32
0
 public float GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset) => throw new NotSupportedException("Regular snap points are not supported.");
 public IReadOnlyList <float> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment alignment)
 {
     // Never has irregular points, so this should never be called
     throw new NotImplementedException();
 }
 float IScrollSnapPointsInfo.GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment alignment, out float offset)
 {
     throw new NotImplementedException();
 }
Esempio n. 35
0
 public static T SnapPoints <T>(this T element, SnapPointsAlignment alignment, SnapPointsType type) where T : ItemsLayout
 {
     element.SnapPointsAlignment = alignment;
     element.SnapPointsType      = type;
     return(element);
 }