|
ZenitUI
Retained-mode C++20 UI framework
|
A virtualized list. More...
#include <VirtualView.hpp>
Public Types | |
| using | ItemFactory = std::function<std::shared_ptr<Layout>(int index)> |
| Signature for an item factory: index → node. | |
Public Member Functions | |
| VirtualView (ItemFactory factory, int itemCount) | |
| Construct with a factory and an item count. | |
| void | setItemFactory (ItemFactory factory) |
| Replace the item factory (useful when instantiating VirtualView from ZMarkup). | |
| int | getItemCount () const noexcept |
| Number of items in the list. | |
| void | setItemCount (int count) |
| Replace the item count. | |
| float | getUniformHeight () const noexcept |
| Return the uniform height, or 0 if variable heights are being measured. | |
| void | setUniformHeight (float px) |
| Set a uniform height for all items. | |
| int | getFirstVisibleItem () const |
| First item whose range overlaps [scrollY, scrollY+height). | |
| int | getLastVisibleItem () const |
| Last visible item, inclusive. | |
| void | scrollToItem (int index) |
| Scroll so that the given item is the first visible. | |
| void | removeAllChildren () override |
| Clear the materialized children and the materialization bookkeeping. | |
| Vec2 | measure (float parent_w, float parent_h) override |
| Public Member Functions inherited from ZenitUI::TLayout< VirtualView, ScrollView > | |
| TLayout (Args &&...args) | |
Forward constructor arguments to Base. | |
| std::shared_ptr< VirtualView > | cls (const std::string &name) |
| Fluent addClass; returns typed shared_ptr<Derived>. | |
| std::shared_ptr< VirtualView > | id (const std::string &node_id) |
| Fluent setId; returns typed shared_ptr<Derived>. | |
| std::shared_ptr< VirtualView > | withRef (const std::string &r) |
| Fluent setRef; returns typed shared_ptr<Derived>. | |
| std::shared_ptr< VirtualView > | size (Value w, Value h) |
| Fluent setSize; returns typed shared_ptr<Derived>. | |
| std::shared_ptr< VirtualView > | passThrough (bool p=true) |
| Fluent setPassThrough; returns typed shared_ptr<Derived>. | |
| std::shared_ptr< VirtualView > | with (std::shared_ptr< Layout > c) |
| Fluent addChild; returns typed shared_ptr<Derived>. | |
| std::shared_ptr< VirtualView > | self () |
| Return shared_from_this() statically cast to Derived. | |
Static Public Member Functions | |
| static std::shared_ptr< VirtualView > | create (ItemFactory factory, int count) |
| Construct with an indexed factory. | |
| static std::shared_ptr< VirtualView > | create (std::function< std::shared_ptr< Layout >()> factory, int count) |
| Construct with an index-agnostic factory. | |
| Static Public Member Functions inherited from ZenitUI::TLayout< VirtualView, ScrollView > | |
| static std::shared_ptr< VirtualView > | create (Args &&...args) |
| Construct a shared_ptr<Derived> and call onBuild(). | |
Public Attributes | |
| std::function< void(Layout *, int)> | onItemCreated |
| Fired each time an item node is materialized. | |
Protected Member Functions | |
| void | onBuild () override |
| Hook: called once after create() finishes constructing the object. | |
| void | arrange (Rect space) override |
| Vec2 | computeIntrinsicSize (float availW, float availH) override |
A virtualized list.
Style tag: "VirtualView". Extends ScrollView (Vertical). Item nodes are added as absolutely-positioned children of the view; the view itself does not lay them out — their top and height come from cumulativeHeights at materialization time.
| ZenitUI::UI::VirtualView::VirtualView | ( | ItemFactory | factory, |
| int | itemCount ) |
Construct with a factory and an item count.
| factory | Called on demand for each item that enters the overscan window. Should be cheap; if it is expensive, cache externally. |
| itemCount | Total number of items. Negative is clamped to 0. |
|
static |
Construct with an indexed factory.
|
static |
Construct with an index-agnostic factory.
All items share the same factory (no index dispatch). Useful for placeholder skeletons or uniform rows.
| int ZenitUI::UI::VirtualView::getFirstVisibleItem | ( | ) | const |
First item whose range overlaps [scrollY, scrollY+height).
| int ZenitUI::UI::VirtualView::getLastVisibleItem | ( | ) | const |
Last visible item, inclusive.
-1 if none.
|
overrideprotectedvirtual |
Hook: called once after create() finishes constructing the object.
Reimplemented from ZenitUI::TLayout< VirtualView, ScrollView >.
|
override |
Clear the materialized children and the materialization bookkeeping.
Called automatically by Layout::removeAllChildren.
| void ZenitUI::UI::VirtualView::scrollToItem | ( | int | index | ) |
Scroll so that the given item is the first visible.
Does not account for the item's height: item index is placed at the top of the viewport. -1 and out-of-range indices are clamped to the nearest valid value.
| void ZenitUI::UI::VirtualView::setItemCount | ( | int | count | ) |
Replace the item count.
Invalidates the cumulative heights; they are rebuilt on the next measure. If the count is unchanged, no-op.
| void ZenitUI::UI::VirtualView::setUniformHeight | ( | float | px | ) |
Set a uniform height for all items.
When positive, disables measurement — this makes huge lists cheap (O(1) height computation), at the cost of assuming all items have the same height. 0 restores measurement mode.
| std::function<void(Layout *, int)> ZenitUI::UI::VirtualView::onItemCreated |
Fired each time an item node is materialized.
Useful for wiring per-item callbacks that need to see the node identity. Fired again on re-materialization when scrolling back to an item that was previously unmaterialized.