5#include <portals/detail/virtual_rows_tree.hpp>
6#include <portals/layout.hpp>
7#include <portals/managed_navigation.hpp>
8#include <portals/model.hpp>
9#include <portals/model_edit.hpp>
15template <
class>
class Model;
21template <
class T>
struct VirtualRowsModelBinding {
22 virtual ~VirtualRowsModelBinding() =
default;
23 virtual std::expected<void, TreeError> replaceModel(ui::Model<T>, ModelRebindOptions) = 0;
25 virtual std::expected<void, TreeError> replaceWindowModel(
const ui::WindowRowsModel<T> &, ModelRebindOptions) {
26 return std::unexpected(TreeError::INVALID_ARGUMENT);
59 std::optional<std::uint64_t>
count;
83struct RowPositionState;
88 std::int32_t height{1};
91struct VirtualRowsState {
92 virtual ~VirtualRowsState() =
default;
93 VirtualRowsOptions options;
94 std::vector<RowPlacement> placements = std::vector<RowPlacement>(0);
95 std::optional<TreeError> failure;
96 std::optional<SourceError> sourceFailure;
97 std::optional<WindowStatus> sourceStatus;
98 std::optional<SourceCursor> sourceRecovery;
99 std::optional<SourceCapabilities> sourceCapabilities;
100 std::optional<std::uint64_t> exactCount;
101 std::uint64_t first{};
102 std::int32_t firstCellOffset{};
103 VirtualRowsPosition position;
104 std::shared_ptr<RowPositionState> positionState;
105 Node<ScrollBar> scrollbar;
106 bool scrollbarVisible{};
108 std::size_t currentSlot{};
109 std::optional<std::size_t> visibleCurrentSlot;
110 std::optional<GraphemeText> currentGlyph;
112 virtual std::expected<void, TreeError> autoHeight(
bool) {
113 return std::unexpected(TreeError::INVALID_ARGUMENT);
116 virtual std::expected<void, TreeError> requestFirst(std::uint64_t) = 0;
117 virtual std::expected<void, TreeError> requestMove(std::int64_t) = 0;
118 virtual std::expected<void, TreeError> requestPage(
bool) = 0;
120 virtual std::expected<void, TreeError> requestAnchor(SourceAnchor, SourceDirection) {
121 return std::unexpected(TreeError::INVALID_ARGUMENT);
124 virtual std::expected<void, TreeError> notifyReady(std::uint64_t) {
125 return std::unexpected(TreeError::INVALID_ARGUMENT);
145 const std::shared_ptr<ui::detail::VirtualRowsState> &state() const noexcept {
152 return state_->first;
157 return state_->failure;
161 std::optional<std::uint64_t>
rowCount() const noexcept {
162 return state_->exactCount;
167 return state_->sourceStatus;
172 return state_->sourceFailure;
177 return state_->sourceRecovery;
182 return state_->sourceCapabilities;
187 return state_->placements.size();
192 return state_->position;
198 static_cast<std::int32_t
>(state_->options.currentIndicator) +
static_cast<std::int32_t
>(state_->scrollbarVisible);
200 state_->options.autoRowHeight ? available.
height : state_->options.rowHeight};
204 std::expected<CellSize, TreeError>
measureChildren(std::span<const MeasuredChild>)
const override {
212 CellSize available)
const override try {
213 std::vector<CellRect> result(0);
214 result.reserve(children.size());
215 for (
const auto &child : children) {
216 if (child.node == state_->scrollbar.id()) {
218 CellRect::from({std::max(0, available.width - 1), 0}, {std::min(1, available.width), available.height});
222 result.push_back(*rect);
225 if (!state_->options.autoRowHeight && child.desired.height > state_->options.rowHeight) {
228 const auto found = std::ranges::find(state_->placements, child.node, [](
const auto &entry) {
229 return entry.node.id();
231 if (found == state_->placements.end()) {
234 const auto leading = std::min(available.width,
static_cast<std::int32_t
>(state_->options.currentIndicator));
235 const auto width = std::max(0, available.width - leading -
static_cast<std::int32_t
>(state_->scrollbarVisible));
236 auto rect =
CellRect::from({leading, found->y}, {width, found->height});
240 result.push_back(*rect);
243 return std::expected<std::vector<CellRect>,
TreeError>(std::in_place, result);
244 }
catch (
const std::bad_alloc &) {
260 if (!state_->options.currentIndicator || !state_->currentGlyph || !state_->position.current ||
261 !state_->visibleCurrentSlot) {
264 const auto index = *state_->visibleCurrentSlot;
265 if (index >= state_->placements.size()) {
268 const std::array<RenderCommand, 1> commands{
269 TextCommand{{0, std::max(0, state_->placements[index].y)},
270 *state_->currentGlyph,
272 CellStyle{.bold = state_->hasFocus, .underline = state_->hasFocus}}};
273 return context.
submit(commands);
277 std::shared_ptr<ui::detail::VirtualRowsState> state_;
288 std::expected<void, TreeError> result;
289 auto changed = tree.
edit(node, [&](
auto &host) {
290 result = host.state()->autoHeight(enabled);
292 return changed ? result : changed;
302 std::expected<void, TreeError> result;
303 const auto changed = tree.
edit(node, [&](
auto &host) {
304 result = host.state()->requestFirst(first);
306 return changed ? result : changed;
315 std::expected<void, TreeError> result;
316 auto edited = tree.
edit(node, [&](
auto &host) {
317 result = host.state()->requestMove(rows);
319 return edited ? result : edited;
328 std::expected<void, TreeError> result;
329 auto changed = tree.
edit(node, [&](
auto &host) {
330 result = host.state()->requestPage(backwards);
332 return changed ? result : changed;
343 std::expected<void, TreeError> result;
344 auto changed = tree.
edit(node, [&](
auto &host) {
345 result = host.state()->requestAnchor(anchor, direction);
347 return changed ? result : changed;
356 std::uint64_t revision) {
357 std::expected<void, TreeError> result;
358 auto changed = tree.
edit(node, [&](
auto &host) {
359 result = host.state()->notifyReady(revision);
361 return changed ? result : changed;
An owning, invariant-preserving half-open cell rectangle.
Definition geometry.hpp:81
CellSize size() const noexcept
Return the normalized cell extents by value; no errors.
static std::expected< CellRect, GeometryError > from(CellPoint origin, CellSize available) noexcept
Create a rectangle after normalizing negative available extents to zero.
Pure container interface; callbacks run inside tree.read and an enclosing tree.frame....
Definition layout.hpp:130
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Borrowed synchronous command sink supplied by the frame owner. submit must consume commands immediate...
Definition widget_types.hpp:66
virtual std::expected< void, TreeError > submit(std::span< const RenderCommand > commands)=0
Borrow commands.
Typed opt-in for custom editor state owned by a delegated row. Custom controls call RowContext::admit...
Definition virtual_rows.hpp:37
virtual void retire() noexcept
Retire the participant after its row identity has closed; never commit/cancel backend work.
Definition virtual_rows.hpp:48
virtual std::expected< void, TreeError > beforeLeave()=0
virtual ~VirtualRowEditParticipant()=default
Release only the participant's own state.
virtual bool unfinished() const noexcept=0
Bounded real widget subtrees, independent of the text-only VirtualList.
Definition virtual_rows.hpp:136
std::size_t mountedRows() const noexcept
Definition virtual_rows.hpp:186
std::expected< void, TreeError > arrange(CellRect local) override
Definition virtual_rows.hpp:249
VirtualRowsPosition position() const noexcept
Definition virtual_rows.hpp:191
std::optional< WindowStatus > windowStatus() const noexcept
Definition virtual_rows.hpp:166
std::expected< void, TreeError > paint(PaintContext &context) override
Definition virtual_rows.hpp:259
std::optional< SourceError > sourceError() const noexcept
Definition virtual_rows.hpp:171
std::optional< TreeError > lastError() const noexcept
Definition virtual_rows.hpp:156
std::expected< std::vector< CellRect >, TreeError > arrangeChildren(std::span< const MeasuredChild > children, CellSize available) const override
Definition virtual_rows.hpp:211
std::uint64_t firstRow() const noexcept
Definition virtual_rows.hpp:151
std::expected< CellSize, TreeError > measureChildren(std::span< const MeasuredChild >) const override
Ignore child measurements.
Definition virtual_rows.hpp:204
std::optional< SourceCapabilities > capabilities() const noexcept
Definition virtual_rows.hpp:181
T VirtualRow
Domain row used by the host's typed observing facade.
Definition virtual_rows.hpp:138
std::optional< SourceCursor > recoveryCursor() const noexcept
Definition virtual_rows.hpp:176
std::expected< CellSize, TreeError > childAvailable(CellSize available) const override
Definition virtual_rows.hpp:196
std::optional< std::uint64_t > rowCount() const noexcept
Definition virtual_rows.hpp:161
Owning cold model declaration; copies share one single-scene registration. Construction does not read...
Definition ui_model.hpp:129
Public Portals API.
Definition action.hpp:8
std::expected< void, TreeError > navigateVirtualRows(WidgetTree &tree, Node< VirtualRows< T > > node, SourceAnchor anchor, SourceDirection direction=SourceDirection::FORWARD)
Request a capability-gated native row/tail/cursor operation.
Definition virtual_rows.hpp:341
std::expected< void, TreeError > setVirtualRowsFirst(WidgetTree &tree, Node< VirtualRows< T > > node, std::uint64_t first)
Request a finite ordinal; mounting occurs at the existing managed service boundary.
Definition virtual_rows.hpp:301
std::expected< void, ManagedError > setVirtualRowsAutoRowHeight(ManagedScene &scene, Node< VirtualRows< T > > node, bool enabled)
Checked managed facade for natural row sizing.
Definition ui_virtual_rows.hpp:943
std::expected< void, TreeError > scrollVirtualRows(WidgetTree &tree, Node< VirtualRows< T > > node, std::int64_t rows)
Accumulate a relative row intent without replacing it with a stale committed position.
Definition virtual_rows.hpp:314
constexpr SizePolicy DEFAULT_VIEWPORT_POLICY
A bounded data viewport fills both axes without requesting the whole model extent.
Definition layout.hpp:53
SourceDirection
Requested traversal; returned rows remain in display order.
Definition window_source.hpp:47
@ FORWARD
Read after the requested gap.
Definition window_source.hpp:48
std::expected< void, TreeError > notifyVirtualRowsReady(WidgetTree &tree, Node< VirtualRows< T > > node, std::uint64_t revision)
Publish a native provider readiness revision through the existing source notifier.
Definition virtual_rows.hpp:355
std::expected< void, TreeError > pageVirtualRows(WidgetTree &tree, Node< VirtualRows< T > > node, bool backwards=false)
Navigate one bounded delivered page, preserving unknown source extent.
Definition virtual_rows.hpp:327
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
@ INVALID_GEOMETRY
Required arranged geometry is absent or translation overflowed.
Definition widget_types.hpp:38
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
@ NO_MEMORY
Allocation failed inside the operation boundary.
Definition widget_types.hpp:33
An owning available extent in terminal columns/rows.
Definition geometry.hpp:44
std::int32_t height
Available number of rows, possibly negative before normalization.
Definition geometry.hpp:48
std::int32_t width
Available number of columns, possibly negative before normalization.
Definition geometry.hpp:46
Small owning paint value, independent of themes and text metrics.
Definition cell_buffer.hpp:35
Bounded retained editing, independent of collection extent.
Definition model_edit.hpp:93
Bounded history options, independent of model row count.
Definition managed_navigation.hpp:38
Logical resource namespace, distinct from its current delivery session. Reuse an existing SourceStamp...
Definition model_position.hpp:21
Owning independent policies for width and height.
Definition layout.hpp:35
Owning navigation intent, including optional capability-gated operations.
Definition window_source.hpp:66
One horizontal text run; controls display placeholders, never line breaks.
Definition render.hpp:24
Bounded real-child row host settings; fixed-height defaults with opt-in natural sizing.
Definition virtual_rows.hpp:69
std::int32_t rowHeight
Positive terminal cell rows per domain row.
Definition virtual_rows.hpp:72
ModelCheckpointOptions checkpoints
Existing bounded source-position history budget.
Definition virtual_rows.hpp:70
std::size_t maxRows
Positive maximum visible assignments; excessive viewport demand is rejected.
Definition virtual_rows.hpp:73
EditOptions editing
Existing common field editing mode and retained field/byte limits.
Definition virtual_rows.hpp:71
bool currentIndicator
Reserve one leading cell for the current-row marker.
Definition virtual_rows.hpp:77
bool scrollbar
Show the existing styled vertical bar when a finite source can scroll.
Definition virtual_rows.hpp:76
std::int64_t maxPendingRows
Positive cap on queued native row moves or natural-mode cell intents.
Definition virtual_rows.hpp:75
bool autoRowHeight
Measure bounded real row compositions at their actual offered width.
Definition virtual_rows.hpp:78
std::size_t overscanRows
Additional native delivered rows for smooth bounded row-step overlap.
Definition virtual_rows.hpp:74
Owning committed row-host orientation; native cursor sources never invent ordinals.
Definition virtual_rows.hpp:53
std::optional< bool > hasAfter
Known forward availability, absent when unknown.
Definition virtual_rows.hpp:61
std::optional< std::uint64_t > count
Exact finite extent; never an estimate.
Definition virtual_rows.hpp:59
bool operator==(const VirtualRowsPosition &other) const =default
std::optional< bool > hasBefore
Known backward availability, absent when unknown.
Definition virtual_rows.hpp:60
std::optional< std::uint64_t > currentIndex
Zero-based finite ordinal, absent for native cursors.
Definition virtual_rows.hpp:56
std::size_t visible
Ready visible row assignments, excluding retained edit state.
Definition virtual_rows.hpp:58
std::optional< std::uint64_t > firstIndex
First visible finite ordinal, absent for native cursors.
Definition virtual_rows.hpp:57
std::optional< RowId > current
Stable current record, independent of keyboard focus.
Definition virtual_rows.hpp:55
ModelResource resource
Exact accepted source identity.
Definition virtual_rows.hpp:54
std::optional< WindowStatus > windowStatus
Native delivery state, absent for finite sources.
Definition virtual_rows.hpp:62
bool editing
Focus is inside the current row's real controls.
Definition virtual_rows.hpp:63
Cold native window delivery capability, with no invented finite extent/current.
Definition ui_virtual_rows.hpp:364