Skip to content

Component VirtualRow

MeowLynxSea edited this page Jun 18, 2026 · 6 revisions

VirtualRow

A virtualised list. Only the rows visible in the scroll viewport (plus a small overdraw) are mounted, no matter how many items the controller reports.

Two variants:

  • virtual_list — variable row heights.
  • uniform_virtual_list — fixed row height (cheaper, but every row must be the same height).
use yororen_ui::headless::label::label;
use yororen_ui::headless::virtual_list::{virtual_list, VirtualListController};

let controller = cx.new(|_| VirtualListController::with_default(10_000));

virtual_list("rows", &controller, cx)
    .row(|ix, _w, cx| label(format!("item-{ix}"), format!("Item {ix}"), cx).render(cx))
    .render(cx)

// later, to update the count:
controller.update(cx, |c, _| c.reset(20_000));

For the fixed-height variant:

use yororen_ui::headless::virtual_list::{uniform_virtual_list, UniformVirtualListController};

let controller = cx.new(|_| UniformVirtualListController::with_default(1_000));
uniform_virtual_list("rows", controller.read(cx).item_count(), &controller, cx)
    .row(|ix, _w, cx| label(format!("row-{ix}"), format!("Row {ix}"), cx).render(cx))
    .render(cx)

Props

Method Purpose
item_count(n) Override the count (otherwise read from the controller on each frame).
alignment(a) ListAlignment::Top (default) / Center / Bottom. virtual_list only.
overdraw(px) Extra pixels above/below the viewport kept mounted. Default 16 px. virtual_list only.
sizing(b) ListSizingBehavior (auto / fixed).
row(closure) Required. Fn(usize, &mut Window, &mut App) -> AnyElement.
on_visible_range_change(closure) Fn(Range<usize>, &mut Window, &mut App) + 'static + Send + Sync.

The controller is owned by the caller — keep it as a field on the parent view. Factories take (id, controller_ref, _cx).

For "load more on scroll", append items in on_visible_range_change when the visible range approaches the end (call controller.append(n)).

See also: ListItem, Tree, Widget-VirtualList.

Clone this wiki locally