Raxol.UI.Layout.ScrollContent behaviour (Raxol v2.6.0)

View Source

Behaviour for content sources that support cursor-based streaming.

Inspired by Pretext's layoutNextLine() cursor-based API, this behaviour allows scrollable containers (Viewport, Table) to request only the visible slice of content instead of materializing the full list.

Implementations can wrap in-memory lists, ETS tables, database queries, or streaming sources. The Viewport component uses this to render only visible elements without holding the entire dataset in memory.

Summary

Callbacks

Returns the height (in rows) of the item at index. Defaults to 1.

Returns a slice of items starting at offset with at most count items.

Returns the total number of items in the content source.

Callbacks

item_height(state, index)

(optional)
@callback item_height(state :: term(), index :: non_neg_integer()) :: pos_integer()

Returns the height (in rows) of the item at index. Defaults to 1.

slice(state, offset, count)

@callback slice(
  state :: term(),
  offset :: non_neg_integer(),
  count :: pos_integer()
) :: [map()]

Returns a slice of items starting at offset with at most count items.

total_count(state)

@callback total_count(state :: term()) :: non_neg_integer()

Returns the total number of items in the content source.