Exemple #1
0
        /// <summary>
        /// Scrolls to item with specifid index.
        /// </summary>
        /// <param name="index">Index.</param>
        protected override void ScrollTo(int index)
        {
            if (!CanOptimize())
            {
                return;
            }

            var first_visible = GetFirstVisibleIndex(true);
            var last_visible  = GetLastVisibleIndex(true);

            if (first_visible > index)
            {
                var item_starts = index * GetItemSize();
                SetScrollValue(item_starts);
            }
            else if (last_visible < index)
            {
                var margin    = (IsHorizontal()) ? layout.GetMarginLeft() : layout.GetMarginTop();
                var item_ends = (index + 1) * GetItemSize() - GetItemSpacing() + margin - GetScrollSize();

                SetScrollValue(item_ends);
            }
        }
Exemple #2
0
        /// <summary>
        /// Scrolls to item with specifid index.
        /// </summary>
        /// <param name="index">Index.</param>
        protected override void ScrollTo(int index)
        {
            if (!CanOptimize())
            {
                return;
            }

            var first_visible = GetFirstVisibleIndex(true);
            var last_visible  = GetLastVisibleIndex(true);

            if (first_visible > index)
            {
                var item_starts = index * (itemHeight + layout.Spacing.y);
                var movement    = 1 - scrollRect.verticalScrollbar.size - (item_starts / FullHeight());
                var value_top   = movement / (1 - scrollRect.verticalScrollbar.size);

                scrollRect.verticalScrollbar.value = value_top;
            }
            else if (last_visible < index)
            {
                var item_ends    = (index + 1) * (itemHeight + layout.Spacing.y) - layout.Spacing.y + layout.GetMarginTop();
                var movement     = (FullHeight() - item_ends) / FullHeight();
                var value_bottom = movement / (1 - scrollRect.verticalScrollbar.size);

                scrollRect.verticalScrollbar.value = value_bottom;
            }
        }
 /// <summary>
 /// Gets the left or top margin.
 /// </summary>
 /// <returns>The margin.</returns>
 public float GetMargin()
 {
     return(IsHorizontal ? Layout.GetMarginLeft() : Layout.GetMarginTop());
 }
Exemple #4
0
        /// <summary>
        /// Gets the item position bottom.
        /// </summary>
        /// <returns>The item position bottom.</returns>
        /// <param name="index">Index.</param>
        protected virtual float GetItemPositionBottom(int index)
        {
            var margin = (IsHorizontal()) ? layout.GetMarginLeft() : layout.GetMarginTop();

            return(GetItemPosition(index) + GetItemSize() - GetItemSpacing() + margin - GetScrollSize());
        }