Exemplo n.º 1
0
        /// <summary>
        /// Calculates the max count of visible items.
        /// </summary>
        protected override void CalculateMaxVisibleItems()
        {
            var spacing_x = GetItemSpacingX();
            var spacing_y = GetItemSpacingY();

            var height = scrollHeight + spacing_y - LayoutBridge.GetFullMarginY();
            var width  = scrollWidth + spacing_x - LayoutBridge.GetFullMarginX();

            if (IsHorizontal())
            {
                ItemsPerRow = Mathf.CeilToInt(width / (itemWidth + spacing_x)) + 1;
                ItemsPerRow = Mathf.Max(2, ItemsPerRow);

                ItemsPerColumn = Mathf.FloorToInt(height / (itemHeight + spacing_y));
                ItemsPerColumn = Mathf.Max(1, ItemsPerColumn);
                ItemsPerColumn = LayoutBridge.ColumnsConstraint(ItemsPerColumn);
            }
            else
            {
                ItemsPerRow = Mathf.FloorToInt(width / (itemWidth + spacing_x));
                ItemsPerRow = Mathf.Max(1, ItemsPerRow);
                ItemsPerRow = LayoutBridge.RowsConstraint(ItemsPerRow);

                ItemsPerColumn = Mathf.CeilToInt(height / (itemHeight + spacing_y)) + 1;
                ItemsPerColumn = Mathf.Max(2, ItemsPerColumn);
            }

            maxVisibleItems = ItemsPerRow * ItemsPerColumn;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get secondary scroll position (for the cross direction).
        /// </summary>
        /// <param name="index">Index.</param>
        /// <returns>Secondary scroll position.</returns>
        protected override float GetScrollPositionSecondary(int index)
        {
            if (IsVirtualizationSupported())
            {
                var scroll_value = IsHorizontal() ? ScrollRectSize.y : ScrollRectSize.x;

                var item_size  = ListRenderer.CalculateSize(index);
                var item_value = IsHorizontal()
                                        ? (item_size.y + LayoutBridge.GetFullMarginY())
                                        : (item_size.x + LayoutBridge.GetFullMarginX());

                if (scroll_value >= item_value)
                {
                    return(base.GetScrollPositionSecondary(index));
                }
            }

            var value = GetNodeIndentation(index);

            return(IsHorizontal() ? value : -value);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the max count of visible items.
        /// </summary>
        protected override void CalculateMaxVisibleItems()
        {
            CalculateItemsSizes(DataSource, false);

            var lowest_width  = ItemSizes.Count > 0 ? ItemSizes.Values.Min(x => x.x) : 1;
            var lowest_height = ItemSizes.Count > 0 ? ItemSizes.Values.Min(x => x.y) : 1;

            var spacing_x = GetItemSpacingX();
            var spacing_y = GetItemSpacingY();

            var height = scrollHeight + spacing_y - LayoutBridge.GetFullMarginY();
            var width  = scrollWidth + spacing_x - LayoutBridge.GetFullMarginX();

            if (IsHorizontal())
            {
                ItemsPerColumn = Mathf.FloorToInt(height / (lowest_height + spacing_y));
                ItemsPerColumn = Mathf.Max(1, ItemsPerColumn);
                ItemsPerColumn = LayoutBridge.ColumnsConstraint(ItemsPerColumn);

                CalculateBlockSizes(ItemsPerColumn);

                ItemsPerRow = RequiredBlocksCount(width) + 1;
                ItemsPerRow = Mathf.Max(2, ItemsPerRow);
            }
            else
            {
                ItemsPerRow = Mathf.FloorToInt(width / (lowest_width + spacing_x));
                ItemsPerRow = Mathf.Max(1, ItemsPerRow);
                ItemsPerRow = LayoutBridge.RowsConstraint(ItemsPerRow);

                CalculateBlockSizes(ItemsPerRow);

                ItemsPerColumn = RequiredBlocksCount(height) + 1;
                ItemsPerColumn = Mathf.Max(2, ItemsPerColumn);
            }

            maxVisibleItems = ItemsPerRow * ItemsPerColumn;
        }