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
| Name | Type | Description |
|---|---|---|
EnableSmoothScroll | bool | Enables smooth wheel and trackpad input. |
SmoothScrollTime | float | Response time in unscaled seconds. |
EnableInfiniteScroll | bool | Repeats the content along one scroll axis. |
EnableVirtualization | bool | Recycles views in a bound list. |
VirtualizationOverscan | int | Extra rows before and after the visible range. |
VirtualizedList | VirtualizedList | Current bound list, or null. |
HasVirtualizedList | bool | Whether a non-disposed list is bound. |
IsVirtualized | bool | Whether the bound list is currently recycling views. |
ItemCount | int | Source item count. |
Methods
| Name | Parameters | Description |
|---|---|---|
CreateVirtualizedList<T>() | T prefab, Action<T, int> bindItem, VirtualizedListSettings settings = null, Action<T, int> unbindItem = null, Action<T> createItem = null, Action<T> destroyItem = null | Creates a typed list using a prefab and bind callback. Returns VirtualizedList<T>. where T : Component. |
RefreshItems() | None | Refreshes tracked items. |
SnapToElement() | int index, float offset = 0 | Animates to an item index, with an optional offset. |
SnapToElement() | RectTransform targetRect | Animates to the specified RectTransform. |
SnapToElementInstant() | int index, float offset = 0 | Moves immediately to an index. |
ScrollToNext() | None | Moves to the next item. |
ScrollToPrevious() | None | Moves to the previous item. |
Events
| Name | Type | Description |
|---|---|---|
onItemFocused | UnityEvent<int> | Invoked with the focused item index. |
Bound list
| Name | Parameters | Description |
|---|---|---|
SetItemCount() | int count, bool resetPosition = false | Updates the number of data items. |
SetLayout() | VirtualizedListSettings settings | Recalculates sizes and layout. |
RefreshItems() | None | Rebinds all visible views or one item. |
RefreshItem() | int index | Rebinds all visible views or one item. |
ScrollToIndex() | int index, float alignment = 0f | Scrolls to a data index. |
EnsureVisible() | int index | Brings an item into the viewport. |
TryGetItem() | int index, out T item | Gets a currently generated view, if present. |
TrimPool() | None | Releases unused pooled views. |
Dispose() | None | Releases the binding and restores content layout. |
Example
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();
}
}