Logo
Layout

Scroll Rect

Smooth scrolling, snapping, infinite content, and virtualized lists

Overview

Evo UI Scroll Rect extends Unity’s ScrollRect. It adds smooth wheel input, snapping, focused-item effects, infinite scrolling, and a data-driven virtualized list.


Usage

Create an Evo UI Scroll Rect and assign its content and viewport.

Choose the scroll axis and movement settings.

Enable Smooth Scroll to soften mouse-wheel and trackpad input.

Add snapping or focused-item scale/fade effects if the view should emphasize a selected item.


Customization

Infinite Scrolling

Enable Infinite Scroll to repeat content along one axis. Use either horizontal or vertical scrolling, not both. Scrollbars retain the original list endpoints.

Virtualization

Virtualization recycles views outside the viewport. Enabling its checkbox does not convert existing child objects into a data list: first bind a prefab and a callback with CreateVirtualizedList<T>(), then call SetItemCount(). The list owns content layout while bound.

Use Virtualization Overscan to keep a few extra views ready beyond the viewport. VirtualizedListSettings.itemSize and spacing are measured along the scroll axis in Canvas units. For variable sizes, provide getItemSize; it is evaluated when item count or layout changes, not on every scroll.


Notes

Virtualized lists are created in Play Mode and support a single row or column. Reused views must have all item-specific content reset in the bind callback. Add persistent callbacks once in createItem, or remove per-item callbacks in unbindItem, so recycling does not accumulate listeners. Dispose the list when replacing it; disposal restores the previous content layout. Smooth scrolling affects wheel/trackpad input; dragging and explicit positioning remain immediate.


Public API

Use ScrollRect in the Evo.UI namespace.

Properties

NameTypeDescription
EnableSmoothScrollboolEnables smooth wheel and trackpad input.
SmoothScrollTimefloatResponse time in unscaled seconds.
EnableInfiniteScrollboolRepeats the content along one scroll axis.
EnableVirtualizationboolRecycles views in a bound list.
VirtualizationOverscanintExtra rows before and after the visible range.
VirtualizedListVirtualizedListCurrent bound list, or null.
HasVirtualizedListboolWhether a non-disposed list is bound.
IsVirtualizedboolWhether the bound list is currently recycling views.
ItemCountintSource item count.

Methods

NameParametersDescription
CreateVirtualizedList<T>()T prefab, Action<T, int> bindItem, VirtualizedListSettings settings = null, Action<T, int> unbindItem = null, Action<T> createItem = null, Action<T> destroyItem = nullCreates a typed list using a prefab and bind callback. Returns VirtualizedList<T>. where T : Component.
RefreshItems()NoneRefreshes tracked items.
SnapToElement()int index, float offset = 0Animates to an item index, with an optional offset.
SnapToElement()RectTransform targetRectAnimates to the specified RectTransform.
SnapToElementInstant()int index, float offset = 0Moves immediately to an index.
ScrollToNext()NoneMoves to the next item.
ScrollToPrevious()NoneMoves to the previous item.

Events

NameTypeDescription
onItemFocusedUnityEvent<int>Invoked with the focused item index.

Bound list

NameParametersDescription
SetItemCount()int count, bool resetPosition = falseUpdates the number of data items.
SetLayout()VirtualizedListSettings settingsRecalculates sizes and layout.
RefreshItems()NoneRebinds all visible views or one item.
RefreshItem()int indexRebinds all visible views or one item.
ScrollToIndex()int index, float alignment = 0fScrolls to a data index.
EnsureVisible()int indexBrings an item into the viewport.
TryGetItem()int index, out T itemGets a currently generated view, if present.
TrimPool()NoneReleases unused pooled views.
Dispose()NoneReleases the binding and restores content layout.

Example

ScrollRectExample.cs
using UnityEngine;
using Evo.UI;

public class ScrollRectExample : MonoBehaviour
{
    [SerializeField] private ScrollRect target;
    [SerializeField] private Button rowPrefab;
    private VirtualizedList<Button> list;

    private void Start()
    {
        target.horizontal = false;
        target.vertical = true;
        target.EnableVirtualization = true;
        list = target.CreateVirtualizedList(rowPrefab,
            (row, index) => row.Text = $"Item {index + 1}",
            new VirtualizedListSettings { itemSize = 48f, spacing = 4f });
        list.SetItemCount(1000);
    }

    private void OnDestroy()
    {
        list?.Dispose();
    }
}

On this page