Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::VirtualList< T > Class Template Reference

One UI-owned view with bounded owning row text and one independent model consumer. Construct with a consumer of the frame's model. Delegate owns its captures and returns owning text; it runs only during preparation and must not perform I/O, mutate models/tree, or retain row borrows. Preparation is transactional on allocation/delegate failure. The retained frame and text survive through render inside WidgetTree::frame. No row widgets, worker, hidden pin or terminal I/O exist. Use tree-checked free mutations; read getters through tree.read. Destroy on the UI owner. More...

#include <virtual_list.hpp>

Inheritance diagram for portals::VirtualList< T >:
portals::VirtualList< T >portals::VirtualList< T > portals::SizedWidget portals::Widget portals::LayoutItem

Public Member Functions

 VirtualList (ModelConsumer< T > consumer, std::function< GraphemeText(const ModelRow< T > &)> delegate, VirtualListOptions options={}, SizePolicy policy=DEFAULT_VIEWPORT_POLICY)
 Own consumer, delegate and options; validation happens on preparation.
 ~VirtualList () override
 Cancel work; worker ownership may outlive this view.
std::uint64_t firstRow () const noexcept
 Integral scroll position, clamped at preparation.
ScrollState scrollState () const noexcept
std::optional< RowId > anchorRow () const noexcept
std::optional< RowId > selection () const noexcept
 Stable identity, retained across model revisions and hidden views.
RowRange visibleRange () const noexcept
 Last successfully prepared visible rows.
RowRange preparedRange () const noexcept
 Last successfully prepared viewport plus overscan.
RangeState rangeState () const noexcept
 Last prepared model readiness; error text is owned by its retained model range.
DataRangeStatus dataStatus () const noexcept
std::expected< CellSize, TreeError > measure (CellSize available) override
 Viewport-sized intrinsic extent, independent of logical row count.
std::expected< void, TreeError > arrange (CellRect local) override
 Remember local bounds without reading/loading/formatting rows.
std::expected< void, TreeError > paint (PaintContext &context) override
 Emit widget-local commands; caller applies surface translation and ancestor clip.
ComputedStyle styleDefaults () const override
Public Member Functions inherited from portals::SizedWidget
 SizedWidget (SizePolicy policy={})
 Own the supplied policies; checked by layout.
SizePolicy sizePolicy () const override
 Copy current policy without borrowing storage.
Public Member Functions inherited from portals::Widget
virtual ~Widget ()=default
 Destroy on UI after the last active tree borrow.
virtual void mount ()
 Called exactly once after attachment; exceptions are reported.
virtual void unmount ()
 Called once before destruction, children first; cleanup continues on exceptions.
virtual bool styleReadOnly () const noexcept
 Read actual view-only state during style staging; false by default.
const std::shared_ptr< const StyleSnapshot > & computedStyle () const noexcept
 Inspect the last atomically installed theme inside tree.read/frame.
std::uint64_t styleRevision () const noexcept
Public Member Functions inherited from portals::LayoutItem
virtual ~LayoutItem ()=default
 Destroy with the implementing widget.

Friends

class ManagedScene
struct ui::detail::Access

Detailed Description

template<class T>
class portals::VirtualList< T >

One UI-owned view with bounded owning row text and one independent model consumer. Construct with a consumer of the frame's model. Delegate owns its captures and returns owning text; it runs only during preparation and must not perform I/O, mutate models/tree, or retain row borrows. Preparation is transactional on allocation/delegate failure. The retained frame and text survive through render inside WidgetTree::frame. No row widgets, worker, hidden pin or terminal I/O exist. Use tree-checked free mutations; read getters through tree.read. Destroy on the UI owner.

Template Parameters
TDomain value exposed by ModelRow<T>. It need not be copyable/default-constructible; this view only borrows const rows during its delegate. The provider must publish immutable transitively owned values and stable nonzero RowId pairs. The copyable delegate owns captures, returns GraphemeText with options.width_policy, and may throw; preparation reports those failures.

Constructor & Destructor Documentation

◆ VirtualList()

template<class T>
portals::VirtualList< T >::VirtualList ( ModelConsumer< T > consumer,
std::function< GraphemeText(const ModelRow< T > &)> delegate,
VirtualListOptions options = {},
SizePolicy policy = DEFAULT_VIEWPORT_POLICY )
inline

Own consumer, delegate and options; validation happens on preparation.

Parameters
consumerIndependent move-only range slot, normally obtained from Model<T>::openRange().
delegateOwning copyable formatter; called only for visible ready rows, with no I/O/mutation.
optionsOwning height, overscan, width-policy and styles.
policyOwning layout constraints inherited by SizedWidget.
Note
Construct through WidgetTree::emplace on UI; allocation/capture failures follow its errors.

Member Function Documentation

◆ anchorRow()

template<class T>
std::optional< RowId > portals::VirtualList< T >::anchorRow ( ) const
inlinenoexcept
Returns
First ready visible row identity retained across hidden periods, or no established anchor.

◆ arrange()

template<class T>
std::expected< void, TreeError > portals::VirtualList< T >::arrange ( CellRect local)
inlineoverridevirtual

Remember local bounds without reading/loading/formatting rows.

Parameters
localOwning parent-local rectangle supplied by layoutTree inside the frame.
Returns
Success after storing the local size; does not prepare rows or invalidate the tree.

Reimplemented from portals::Widget.

◆ dataStatus()

template<class T>
DataRangeStatus portals::VirtualList< T >::dataStatus ( ) const
inlinenoexcept
Returns
Owning facts of this successful preparation, without reading or pinning the model. Call through tree.read on UI. Hidden/unprepared views return prepared=false.

◆ firstRow()

template<class T>
std::uint64_t portals::VirtualList< T >::firstRow ( ) const
inlinenoexcept

Integral scroll position, clamped at preparation.

Returns
Integral intended scroll position, clamped at the last successful preparation.

◆ measure()

template<class T>
std::expected< CellSize, TreeError > portals::VirtualList< T >::measure ( CellSize available)
inlineoverridevirtual

Viewport-sized intrinsic extent, independent of logical row count.

Parameters
availableBorrowed-by-value cell bounds; negative extents normalize to zero.
Returns
Normalized available extent without model access, formatting, allocation or invalidation.

Reimplemented from portals::Widget.

◆ paint()

template<class T>
std::expected< void, TreeError > portals::VirtualList< T >::paint ( PaintContext & context)
inlineoverridevirtual

Emit widget-local commands; caller applies surface translation and ancestor clip.

Parameters
contextSynchronous borrowed sink; rendered text must not outlive the enclosing tree.frame.
Returns
Success, WOULD_BLOCK for dirty/unprepared content, INVALID_GEOMETRY after resize, or the sink error. Caller must discard partial commands on error.
Note
UI frame only; no I/O, model reads, delegate calls or invalidation.

Reimplemented from portals::Widget.

◆ preparedRange()

template<class T>
RowRange portals::VirtualList< T >::preparedRange ( ) const
inlinenoexcept

Last successfully prepared viewport plus overscan.

Returns
Owning viewport-plus-overscan interval; hidden/unprepared lists return an empty interval.

◆ rangeState()

template<class T>
RangeState portals::VirtualList< T >::rangeState ( ) const
inlinenoexcept

Last prepared model readiness; error text is owned by its retained model range.

Returns
Last prepared ready/pending/error state; an unprepared/hidden list reports pending.

◆ scrollState()

template<class T>
ScrollState portals::VirtualList< T >::scrollState ( ) const
inlinenoexcept
Returns
Owning logical/raster scroll position; reads require the UI owner's tree.read.

◆ selection()

template<class T>
std::optional< RowId > portals::VirtualList< T >::selection ( ) const
inlinenoexcept

Stable identity, retained across model revisions and hidden views.

Returns
Owning stable ID, including an offscreen/removed ID, or nullopt when cleared.

◆ styleDefaults()

template<class T>
ComputedStyle portals::VirtualList< T >::styleDefaults ( ) const
inlineoverridevirtual
Returns
Owning manual row appearances beneath theme declarations.

Reimplemented from portals::Widget.

◆ visibleRange()

template<class T>
RowRange portals::VirtualList< T >::visibleRange ( ) const
inlinenoexcept

Last successfully prepared visible rows.

Returns
Owning interval of the last prepared visible rows, or an empty interval before preparation.

The documentation for this class was generated from the following file: