Пример #1
0
        private void GetItemsInView(int offset, int viewportWidth, out int leftIndex, out int leftInView, out int centerIndex, out int rightIndex, out int rightInView)
        {
            leftIndex = leftInView = centerIndex = rightIndex = rightInView = -1;

            int count = VisibleChildren.Count;

            if (count == 0)
            {
                return;
            }

            for (int index = 0; index < count; ++index)
            {
                StartViewItem child = _visibleChildren[index];

                int leftOffset  = child.StartPosition + offset;
                int rightOffset = leftOffset + child.ItemWidth - 1;

                if (leftOffset <= 0 && rightOffset >= 0)
                {
                    leftIndex  = index;
                    leftInView = Math.Min(viewportWidth, child.ItemWidth + leftOffset);
                }

                if (leftOffset < viewportWidth && rightOffset >= viewportWidth)
                {
                    rightIndex  = index;
                    rightInView = Math.Min(viewportWidth, viewportWidth - leftOffset);
                }

                if (leftOffset > 0 && rightOffset < viewportWidth)
                {
                    centerIndex = index;
                }

                if (index == 0 && leftInView == -1)
                {
                    leftInView = leftOffset;
                }

                if (index == count - 1 && rightInView == -1)
                {
                    rightInView = viewportWidth - rightOffset - 1;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the arrange pass for the control.
        /// </summary>
        ///
        /// <returns>
        /// Render size.
        /// </returns>
        /// <param name="finalSize">Final size.</param>
        protected override Size ArrangeOverride(Size finalSize)
        {
            _itemStops.Clear();
            double x         = 0;
            Rect   finalRect = new Rect(0, 0, 0, finalSize.Height);

            for (int index = 0; index < _visibleChildren.Count; ++index)
            {
                StartViewItem child = _visibleChildren[index];
                finalRect.X = child.StartPosition = (int)x;
                _itemStops.Add(new ItemStop(child, child.StartPosition));
                finalRect.Width = Owner.ViewportWidth;
                child.ItemWidth = (int)finalRect.Width;
                child.Arrange(finalRect);
                x += finalRect.Width;
            }

            Owner.RequestAdjustSelection();

            return(finalSize);
        }
Пример #3
0
 public ItemStop(StartViewItem item, int position)
 {
     Item     = item;
     Position = position;
 }
Пример #4
0
        internal void GetSnapOffset(int offset, int viewportWidth, int direction, out int snapTo, out int newDirection, out StartViewItem newSelection)
        {
            int snapThreshold = viewportWidth / SnapThresholdDivisor;

            snapTo       = offset;
            newDirection = direction;
            newSelection = _selectedItem;

            if (VisibleChildren.Count == 0)
            {
                return;
            }

            foreach (ItemStop itemStop in _itemStops)
            {
                if (itemStop.Position == -offset)
                {
                    newSelection = itemStop.Item;
                    return;
                }
            }

            int leftIndex;
            int leftInView;
            int centerIndex;
            int rightIndex;
            int rightInView;

            GetItemsInView(offset, viewportWidth, out leftIndex, out leftInView, out centerIndex, out rightIndex, out rightInView);

            if (leftIndex == rightIndex && leftIndex != -1)
            {
                newSelection = _selectedItem = _visibleChildren[leftIndex];
            }
            else
            {
                if (leftIndex == -1)
                {
                    leftIndex = _visibleChildren.Count - 1;
                }

                if (rightIndex == -1)
                {
                    rightIndex = 0;
                }

                int index;
                if (direction < 0)
                {
                    if (rightInView > snapThreshold)
                    {
                        index        = GetBestIndex(centerIndex, rightIndex, leftIndex);
                        newDirection = -1;
                    }
                    else
                    {
                        index        = GetBestIndex(leftIndex, centerIndex, rightIndex);
                        newDirection = 1;
                    }
                }
                else if (direction > 0)
                {
                    if (leftInView > snapThreshold)
                    {
                        index        = StartViewPanel.GetBestIndex(leftIndex, centerIndex, rightIndex);
                        newDirection = 1;
                    }
                    else
                    {
                        index        = StartViewPanel.GetBestIndex(centerIndex, rightIndex, leftIndex);
                        newDirection = -1;
                    }
                }
                else if (centerIndex != -1)
                {
                    index        = centerIndex;
                    newDirection = -1;
                }
                else if (leftInView > rightInView)
                {
                    index        = leftIndex;
                    newDirection = -1;
                }
                else
                {
                    index        = rightIndex;
                    newDirection = 1;
                }

                _selectedItem = _visibleChildren[index];
                snapTo        = -_selectedItem.StartPosition;
                newSelection  = _selectedItem;
            }
        }