Example #1
0
 /// <summary>
 /// Gets the scroll position in pixels from the start of the scroller based on the dataIndex
 /// </summary>
 /// <param name="dataIndex">The data index to look for</param>
 /// <param name="insertPosition">Do we want the start or end of the cell view's position</param>
 /// <returns></returns>
 public float GetScrollPositionForDataIndex(int dataIndex, CellViewPositionEnum insertPosition)
 {
     return GetScrollPositionForCellViewIndex(loop ? _delegate.GetNumberOfCells(this) + dataIndex : dataIndex, insertPosition);
 }
Example #2
0
        public void JumpToDataIndex(int dataIndex,
            CellViewPositionEnum position = CellViewPositionEnum.Before,
            bool useSpacing = true)
        {
            // if looping is on, we need to jump to the middle set of data, otherwise just use the dataIndex for the cellIndex
            ScrollPosition = GetScrollPositionForDataIndex(dataIndex, position);

            // if spacing is used, adjust the final position
            if (useSpacing)
            {
                if (position == CellViewPositionEnum.Before)
                    ScrollPosition = _scrollPosition - spacing;
                else
                    ScrollPosition = _scrollPosition + spacing;
            }
        }
Example #3
0
        /// <summary>
        /// Gets the scroll position in pixels from the start of the scroller based on the cellViewIndex
        /// </summary>
        /// <param name="cellViewIndex">The cell index to look for. This is used instead of dataIndex in case of looping</param>
        /// <param name="insertPosition">Do we want the start or end of the cell view's position</param>
        /// <returns></returns>
        public float GetScrollPositionForCellViewIndex(int cellViewIndex, CellViewPositionEnum insertPosition)
        {
            if (NumberOfCells == 0) return 0;

            if (cellViewIndex == 0 && insertPosition == CellViewPositionEnum.Before)
            {
                return 0;
            }
            else
            {
                if (cellViewIndex < _cellViewOffsetArray.Count)
                {
                    // the index is in the range of cell view offsets

                    if (insertPosition == CellViewPositionEnum.Before)
                    {
                        // return the previous cell view's offset + the spacing between cell views
                        return _cellViewOffsetArray[cellViewIndex - 1] + spacing + (scrollDirection == ScrollDirectionEnum.Vertical ? padding.top : padding.left);
                    }
                    else
                    {
                        // return the offset of the cell view (offset is after the cell)
                        return _cellViewOffsetArray[cellViewIndex] + (scrollDirection == ScrollDirectionEnum.Vertical ? padding.top : padding.left);
                    }
                }
                else
                {
                    // get the start position of the last cell (the offset of the second to last cell)
                    return _cellViewOffsetArray[_cellViewOffsetArray.Count - 2];
                }
            }
        }