Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
managed_navigation_views.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5// Included after ManagedScene and its navigation records are complete.
6namespace portals {
7namespace detail {
9inline bool hasModelRestoreIntent(const ModelViewCheckpoint &value) noexcept {
10 return value.current || value.reading || !value.selection.rows().empty() ||
11 unresolvedPosition(value.currentResolution) || unresolvedPosition(value.readingResolution) ||
12 unresolvedPosition(value.selection.resolution());
13}
14
16} // namespace detail
17
18template <class T>
19std::expected<ManagedNavigation, ManagedError> ManagedScene::navigation(ManagedModel<T> model,
20 NavigationOptions options) {
21 auto source = modelSource(model, root_);
22
23 if (!source) {
24 return std::unexpected(source.error());
25 }
26 if ((*source)->navigationResource.identity.instance) {
27 const auto resource = (*source)->navigationResource;
28
29 return makeModelNavigation(model, resource, resource.identity, options, false);
30 }
31
32 auto resource = ModelResource::create();
33
34 return resource ? makeModelNavigation(model, *resource, resource->identity, options, false)
35 : std::unexpected(error(ManagedPhase::STATE, root_, detail::navigationTreeError(resource.error())));
36}
37
38template <class T>
39std::expected<ManagedNavigation, ManagedError> ManagedScene::navigation(ManagedModel<T> model, ModelResource resource,
40 SourceStamp session,
41 NavigationOptions options) {
42 return makeModelNavigation(model, resource, session, options, true);
43}
44
45template <class T>
46std::expected<ManagedNavigation, ManagedError>
47ManagedScene::makeModelNavigation(ManagedModel<T> model, ModelResource resource, SourceStamp session,
48 NavigationOptions options, bool explicitDomain) {
49 auto source = modelSource(model, root_);
50
51 if (!source) {
52 return std::unexpected(source.error());
53 }
54 if ((*source)->navigationResource.identity.instance && (*source)->navigationResource != resource) {
55 return std::unexpected(error(ManagedPhase::STATE, root_, TreeError::INVALID_ARGUMENT));
56 }
57
58 auto pinned = (*source)->pin();
59
60 if (!pinned) {
61 return std::unexpected(error(ManagedPhase::STATE, root_, pinned.error()));
62 }
63
64 try {
65 detail::ManagedNavigationRecord::Capture capture =
66 [](const std::shared_ptr<detail::ManagedNavigationRecord> &record,
67 RowId id) -> std::expected<ModelBookmark, TreeError> {
68 auto source = std::dynamic_pointer_cast<detail::ManagedModelSourceOf<T>>(record->model.lock());
69
70 if (!source || source->retired || !source->frame) {
71 return std::unexpected(TreeError::CLOSED);
72 }
73 if (!source->frame->dataRevision()) {
74 if (record->bookmark && record->bookmark->resource() != record->resource) {
75 return std::unexpected(TreeError::WOULD_BLOCK);
76 }
77 auto unavailable = record->setPosition(record->bookmark, PositionResolution::UNSUPPORTED);
78 return std::unexpected(unavailable ? TreeError::WOULD_BLOCK : unavailable.error());
79 }
80
81 auto location = source->frame->locateRow(id);
82
83 if (!location) {
84 return std::unexpected(location.error());
85 }
86 if (location->state != RowLookupState::FOUND) {
87 return std::unexpected(TreeError::WOULD_BLOCK);
88 }
89
90 auto bookmark = ModelBookmark::create(
91 record->resource,
92 {PositionKind::ITEM, id, location->index, source->frame->dataRevision(), PositionAffinity::FORWARD}, {},
93 record->options.bookmarks);
94
95 return bookmark ? std::expected<ModelBookmark, TreeError>(std::move(*bookmark))
96 : std::unexpected(detail::navigationTreeError(bookmark.error()));
97 };
98 std::function<std::expected<void, TreeError>(const std::shared_ptr<detail::ManagedNavigationRecord> &)> sync =
99 [](const auto &record) -> std::expected<void, TreeError> {
100 auto source = std::dynamic_pointer_cast<detail::ManagedModelSourceOf<T>>(record->model.lock());
101
102 if (!source || source->retired || !source->frame) {
103 record->close();
104
105 return {};
106 }
107 if (source->origin) {
108 auto live = source->origin->check();
109
110 if (!live) {
111 if (source->origin->retired || source->origin->closed) {
112 record->close();
113
114 return {};
115 }
116
117 return std::unexpected(live.error());
118 }
119 }
120
121 const auto frame = *source->frame;
122 const auto revision = frame.dataRevision();
123 const auto publication = frame.revision();
124
125 if (record->history && record->history->pending) {
126 return record->owner->template retryCanonicalRestore<T>(record, source);
127 }
128 if (record->frameRevision == publication) {
129 return {};
130 }
131 if (!revision) {
132 // Revision zero is valid for data-only views, but cannot qualify a bookmark.
133 record->frameRevision = publication;
134 return {};
135 }
136
137 auto resolver = FinitePositionResolver<T>::create(record->resource, record->session, frame.snapshot(),
138 record->changes.toRevision() == revision ? record->changes
139 : PositionChangeMap{});
140
141 if (!resolver) {
142 return std::unexpected(detail::navigationTreeError(resolver.error()));
143 }
144
145 record->cancel();
146 for (bool reading : {false, true}) {
147 auto bookmark = reading ? record->readingBookmark : record->bookmark;
148
149 if (record->closed) {
150 return {};
151 }
152 if (!bookmark) {
153 continue;
154 }
155
156 auto channel = (reading ? record->reading : record->current).snapshot();
157
158 if (!channel) {
159 return std::unexpected(channel.error());
160 }
161
162 const auto outcome = (*channel)->value.resolution;
163 const bool completed = outcome == PositionResolution::EXACT || outcome == PositionResolution::NEAREST;
164
165 // Preserve an earlier successful channel while retrying unfinished work on a newer publication.
166 if (bookmark->position().revision == revision && completed) {
167 continue;
168 }
169
170 const auto operation = record->operation;
171 auto position = bookmark->position();
172 std::optional<PositionReply> reply;
173
174 if (bookmark->resource() == record->resource && position.kind == PositionKind::ITEM &&
175 position.revision <= revision && bookmark->metadata().empty()) {
176 auto location = frame.locateRow(position.row);
177
178 if (!location) {
179 return std::unexpected(location.error());
180 }
181 if (record->closed || operation != record->operation) {
182 return {};
183 }
184 if (location->state == RowLookupState::FOUND) {
185 // An indexed surviving identity needs no row payload or completion overlay.
186 position.offset = location->index;
187 position.revision = revision;
188 reply = PositionReply{record->resource, record->session, revision, 1, PositionResolution::EXACT, position};
189 }
190 }
191 if (!reply) {
192 PositionRequest request{record->session, revision, 1, *bookmark};
193 auto resolved = resolver->resolve(request);
194
195 if (!resolved) {
196 return std::unexpected(detail::navigationTreeError(resolved.error()));
197 }
198 if (record->closed || operation != record->operation) {
199 return {};
200 }
201
202 reply = std::move(*resolved);
203 }
204
205 if (reply->state == PositionResolution::EXACT || reply->state == PositionResolution::NEAREST) {
206 auto updated =
207 ModelBookmark::create(record->resource, reply->position, bookmark->metadata(), record->options.bookmarks);
208
209 if (!updated) {
210 return std::unexpected(detail::navigationTreeError(updated.error()));
211 }
212
213 bookmark = std::move(*updated);
214 } else if (reply->state == PositionResolution::EMPTY) {
215 bookmark.reset();
216 }
217
218 auto applied = record->setPosition(std::move(bookmark), reply->state, reading);
219
220 if (!applied) {
221 return applied;
222 }
223 }
224
225 record->frameRevision = publication;
226
227 return {};
228 };
229 auto captureOwner = std::make_shared<detail::ManagedNavigationRecord::Capture>(std::move(capture));
230 auto syncOwner = std::make_shared<detail::ManagedNavigationRecord::Synchronize>(std::move(sync));
231 auto result = navigation(resource, session, options);
232
233 if (!result) {
234 return result;
235 }
236
237 auto record = result->record_.lock();
238
239 if (!(*source)->navigationResource.identity.instance) {
240 (*source)->navigationResource = resource;
241 }
242 (*source)->navigationExplicit = (*source)->navigationExplicit || explicitDomain;
243
244 record->finite = true;
245 record->model = *source;
246 record->frameRevision = (*source)->frame->revision();
247 record->capture = std::move(captureOwner);
248 record->synchronize = std::move(syncOwner);
249
250 return result;
251 } catch (const std::bad_alloc &) {
252 return std::unexpected(error(ManagedPhase::STATE, root_, TreeError::NO_MEMORY));
253 }
254}
255
256template <class T>
257std::expected<void, ManagedError> ManagedScene::bindNavigation(Node<VirtualList<T>> node, ManagedNavigation navigation,
258 NavigationBindingOptions options) {
259 return bindNavigationView<T>(node, std::move(navigation), options);
260}
261
262template <class T>
263std::expected<void, ManagedError> ManagedScene::bindNavigation(Node<VirtualTable<T>> node, ManagedNavigation navigation,
264 NavigationBindingOptions options) {
265 return bindNavigationView<T>(node, std::move(navigation), options);
266}
267
268template <class T, class W>
269std::expected<void, ManagedError> ManagedScene::bindNavigationView(Node<W> node, ManagedNavigation navigation,
270 NavigationBindingOptions options) {
271 auto allowed = boundary(ManagedPhase::BIND, node);
272
273 if (!allowed) {
274 return allowed;
275 }
276
277 auto record = navigation.lock();
278 auto entry = find(node);
279 auto source = entry ? std::dynamic_pointer_cast<detail::ManagedModelSourceOf<T>>(entry->viewSource.lock()) : nullptr;
280
281 if (!record || !source || (*record)->scene != root_.id() || !(*record)->finite ||
282 (!options.current && !options.readingAnchor) ||
285 (options.projection == NavigationProjection::SAME_MODEL && (*record)->model.lock() != source)) {
286 return std::unexpected(error(ManagedPhase::BIND, node, !record ? record.error() : TreeError::INVALID_ARGUMENT));
287 }
288 if (std::ranges::any_of(navigation_->bindings, [&](const auto &binding) {
289 return binding->node == node;
290 })) {
291 return std::unexpected(error(ManagedPhase::BIND, node, TreeError::INVALID_ARGUMENT));
292 }
293
294 struct BindingState {
295 std::optional<std::uint64_t> offset;
296 std::uint64_t modelRevision{};
297 std::uint64_t currentRevision{};
298 std::uint64_t readingRevision{};
299 std::optional<std::uint64_t> input;
300 std::uint64_t inputRevision{};
301 std::optional<std::uint64_t> pendingInput;
302 std::uint64_t pendingSourceRevision{};
303 std::uint64_t pendingCurrentRevision{};
304 bool readingInput{};
305 bool ensurePending{};
306 };
307
308 try {
309 auto state = std::make_shared<BindingState>();
310 auto binding = std::make_shared<detail::ManagedNavigationBinding>();
311
312 binding->node = node;
313 binding->context = *record;
314 binding->options = options;
315 binding->stage = [this, node, options](const auto &base, ModelRebindOptions policy, const auto &history,
316 const auto *position, const void *override) {
317 auto source = std::dynamic_pointer_cast<detail::ManagedModelSourceOf<T>>(base);
318 if (!source) {
319 return std::expected<std::unique_ptr<detail::PreparedModelViewChange>, ManagedError>(
320 std::unexpected(error(ManagedPhase::INPUT, node, TreeError::INVALID_ARGUMENT)));
321 }
322 auto prepared = override ? *static_cast<const std::optional<ManagedViewHandler<T>> *>(override)
323 : std::optional<ManagedViewHandler<T>>{};
324 return prepareViewModelChange<T>(node, source, std::move(prepared), policy, history, position, &options);
325 };
326 binding->installed = [this, node, navigation, state, options](const detail::ModelViewCheckpoint *value,
327 const detail::ModelRestoreChannels *channels) {
328 auto record = navigation.record_.lock();
329 auto entry = find(node);
330 auto source =
331 entry ? std::dynamic_pointer_cast<detail::ManagedModelSourceOf<T>>(entry->viewSource.lock()) : nullptr;
332 auto preparation = entry ? entry->viewPrepare.template target<ViewPreparation<T, W>>() : nullptr;
333 if (value && channels) {
334 if (!record || !preparation || !preparation->restoration || !preparation->restoration->pending) {
335 return;
336 }
337 auto restoration = preparation->restoration;
338 if (channels->current && options.current) {
339 restoration->pending->current = value->current;
340 restoration->pending->currentResolution = value->currentResolution;
341 if (auto current = record->current.snapshot()) {
342 state->currentRevision = (*current)->revision;
343 restoration->currentRevision = (*current)->revision;
344 }
345 }
346 if (channels->reading && options.readingAnchor) {
347 restoration->pending->reading = value->reading;
348 restoration->pending->readingResolution = value->readingResolution;
349 if (auto reading = record->reading.snapshot()) {
350 state->readingRevision = (*reading)->revision;
351 restoration->readingRevision = (*reading)->revision;
352 }
353 }
354 if (channels->selection) {
355 restoration->pending->selection = value->selection;
356 restoration->pending->selectedPositions = value->selectedPositions;
357 if (auto selection = record->selection.snapshot()) {
358 restoration->selectionRevision = (*selection)->revision;
359 }
360 }
361 return;
362 }
363 *state = {};
364 if (record && source && source->frame) {
365 state->modelRevision = source->frame->dataRevision();
366 if (auto current = record->current.snapshot()) {
367 state->currentRevision = (*current)->revision;
368 }
369 if (auto reading = record->reading.snapshot()) {
370 state->readingRevision = (*reading)->revision;
371 }
372 if (preparation && preparation->restoration) {
373 preparation->restoration->context = record;
374 preparation->restoration->currentRevision = state->currentRevision;
375 preparation->restoration->readingRevision = state->readingRevision;
376 if (auto selection = record->selection.snapshot()) {
377 preparation->restoration->selectionRevision = (*selection)->revision;
378 }
379 }
380 }
381 };
382 binding->before = [this, node, navigation, options, state]() -> std::expected<void, TreeError> {
383 auto record = navigation.lock();
384 auto entry = find(node);
385 auto source =
386 entry ? std::dynamic_pointer_cast<detail::ManagedModelSourceOf<T>>(entry->viewSource.lock()) : nullptr;
387
388 if (!record || !source || source->retired || !source->frame) {
389 return !record && record.error() != TreeError::CLOSED ? std::unexpected(record.error())
390 : std::expected<void, TreeError>{};
391 }
392
393 if (!source->frame->dataRevision()) {
394 return {};
395 }
396 std::uint64_t offset{};
397 auto read = app_.tree().read(node, [&](const W &view) {
398 state->input = view.intent_;
399 state->inputRevision = view.intent_revision_;
400 offset = view.scrollState().rasterOffset();
401 });
402
403 if (!read) {
404 return read;
405 }
406
407 const auto revision = source->frame->dataRevision();
408
409 bool validInput = state->input && state->inputRevision == revision;
410 const bool scrolled =
411 state->offset && *state->offset != offset && !validInput && state->modelRevision == revision;
412
413 state->readingInput = options.readingAnchor && scrolled;
414 if (scrolled) {
415 state->ensurePending = false;
416 }
417 auto current = (*record)->current.snapshot();
418 auto reading = (*record)->reading.snapshot();
419
420 if (!current || !reading) {
421 return std::unexpected(!current ? current.error() : reading.error());
422 }
423
424 bool staleInput{};
425 if (validInput) {
426 const bool samePending =
427 state->pendingInput == state->input && state->pendingSourceRevision == state->inputRevision;
428
429 staleInput = samePending && state->pendingCurrentRevision != (*current)->revision;
430 if (staleInput) {
431 validInput = false;
432 state->input.reset();
433 state->pendingInput.reset();
434 } else if (!samePending) {
435 state->pendingInput = state->input;
436 state->pendingSourceRevision = state->inputRevision;
437 state->pendingCurrentRevision = (*current)->revision;
438 }
439 } else {
440 state->pendingInput.reset();
441 }
442
443 const bool currentChanged = (*current)->revision != state->currentRevision;
444 const bool modelChanged = revision != state->modelRevision;
445
446 if (options.current && !validInput && (currentChanged || modelChanged || state->ensurePending)) {
447 auto selected = (*current)->value.row;
448 if ((*current)->value.resolution != PositionResolution::EXACT &&
449 (*current)->value.resolution != PositionResolution::NEAREST) {
450 selected.reset();
451 }
452
453 if (selected) {
454 auto location = source->frame->locateRow(*selected);
455
456 if (!location) {
457 return std::unexpected(location.error());
458 }
459 if (location->state != RowLookupState::FOUND) {
460 selected.reset();
461 }
462 }
463
464 std::optional<RowId> previous;
465 read = app_.tree().read(node, [&](const W &view) {
466 previous = view.selection();
467 });
468
469 if (!read) {
470 return read;
471 }
472 if (previous != selected || staleInput) {
473 auto changed = [&] {
474 if constexpr (std::same_as<W, VirtualList<T>>) {
475 return setVirtualListSelection(app_.tree(), node, selected);
476 } else {
477 return setVirtualTableSelection(app_.tree(), node, selected);
478 }
479 }();
480
481 if (!changed) {
482 return changed;
483 }
484 }
485 if (selected && (currentChanged || state->ensurePending)) {
486 auto visible = [&] {
487 if constexpr (std::same_as<W, VirtualList<T>>) {
488 return ensureVirtualListVisible(app_.tree(), node, *source->frame, *selected);
489 } else {
490 return ensureVirtualTableVisible(app_.tree(), node, *source->frame, *selected);
491 }
492 }();
493
494 if (!visible && visible.error() != TreeError::WOULD_BLOCK) {
495 return std::unexpected(visible.error());
496 }
497
498 state->ensurePending = !visible;
499 } else if (!selected) {
500 state->ensurePending = false;
501 }
502 }
503
504 if (options.readingAnchor && !validInput && !state->readingInput &&
505 ((*reading)->revision != state->readingRevision || modelChanged) && (*reading)->value.row &&
506 ((*reading)->value.resolution == PositionResolution::EXACT ||
507 (*reading)->value.resolution == PositionResolution::NEAREST)) {
508 auto location = source->frame->locateRow(*(*reading)->value.row);
509
510 if (!location) {
511 return std::unexpected(location.error());
512 }
513 if (location->state == RowLookupState::FOUND) {
514 auto changed = [&] {
515 if constexpr (std::same_as<W, VirtualList<T>>) {
516 return setVirtualListFirst(app_.tree(), node, location->index);
517 } else {
518 return setVirtualTableFirst(app_.tree(), node, location->index);
519 }
520 }();
521
522 if (!changed) {
523 return changed;
524 }
525 }
526 }
527
528 state->currentRevision = (*current)->revision;
529 state->readingRevision = (*reading)->revision;
530
531 return {};
532 };
533 binding->after = [this, node, navigation, options, state]() -> std::expected<void, TreeError> {
534 auto record = navigation.lock();
535 auto entry = find(node);
536 auto source =
537 entry ? std::dynamic_pointer_cast<detail::ManagedModelSourceOf<T>>(entry->viewSource.lock()) : nullptr;
538
539 if (!record || !source || source->retired || !source->frame) {
540 return !record && record.error() != TreeError::CLOSED ? std::unexpected(record.error())
541 : std::expected<void, TreeError>{};
542 }
543
544 if (!source->frame->dataRevision()) {
545 return {};
546 }
547 const auto currentBefore = (*record)->current.snapshot();
548 const auto readingBefore = (*record)->reading.snapshot();
549 if (!currentBefore || !readingBefore) {
550 return std::unexpected(!currentBefore ? currentBefore.error() : readingBefore.error());
551 }
552 const auto lifetime = std::weak_ptr(lifetime_);
553 const auto owner = *record;
554 auto finish = [&](std::expected<void, TreeError> result) {
555 if (!lifetime.expired() && !closed_ && navigation_ && !owner->closed) {
556 auto current = owner->current.snapshot();
557 auto reading = owner->reading.snapshot();
558 if ((current && (*current)->revision != (*currentBefore)->revision) ||
559 (reading && (*reading)->revision != (*readingBefore)->revision)) {
560 // This requests the latest shared state, even after partial success
561 // or a newer nested operation. No old node/position is retained.
562 navigation_->refreshAfterLayout = true;
563 }
564 }
565 return result;
566 };
567 auto stillBound = [&]() -> std::expected<bool, TreeError> {
568 if (lifetime.expired() || closed_ || source->retired || !source->frame) {
569 return false;
570 }
571 auto bound = find(node);
572 if (!bound || bound->viewSource.lock() != source) {
573 return false;
574 }
575 auto live = app_.tree().read(node, [](const W &) {
576 });
577 if (!live && live.error() != TreeError::STALE_NODE && live.error() != TreeError::CLOSED) {
578 return std::unexpected(live.error());
579 }
580 return static_cast<bool>(live);
581 };
582
583 std::optional<RowId> selected;
584 std::optional<RowId> anchor;
585 bool consumed{};
586 bool materialized{};
587 std::uint64_t offset{};
588 auto read = app_.tree().read(node, [&](const W &view) {
589 selected = view.selection();
590 anchor = view.anchorRow();
591 consumed = !view.intent_;
592 if (state->input && consumed && view.prepared_ &&
593 view.prepared_->frame.dataRevision() == state->inputRevision) {
594 const auto first = view.prepared_->window.visible.first;
595 const auto index = *state->input;
596
597 if (index >= first && index - first < view.prepared_->rows.size()) {
598 materialized = selected && view.prepared_->rows[static_cast<std::size_t>(index - first)].id == selected;
599 }
600 }
601 offset = view.scrollState().rasterOffset();
602 });
603
604 if (!read) {
605 return finish(read);
606 }
607 if (options.current && materialized && selected && state->inputRevision == source->frame->dataRevision()) {
608 const auto operation = (*record)->operation;
609 auto updated = navigation.navigate(*selected);
610
611 if (!updated) {
612 if (owner->editVetoed && !lifetime.expired() && !closed_) {
613 navigation_->refreshAfterLayout = true;
614 auto invalidated = app_.tree().invalidate(node, Invalidation::LAYOUT);
615 return finish(invalidated);
616 }
617 return finish(updated);
618 }
619 auto live = stillBound();
620 if (!live || !*live || owner->closed || owner->operation != operation + 1) {
621 return finish(!live ? std::unexpected(live.error()) : std::expected<void, TreeError>{});
622 }
623 }
624 record = navigation.lock();
625 if (!record) {
626 return finish(record.error() == TreeError::CLOSED ? std::expected<void, TreeError>{}
627 : std::unexpected(record.error()));
628 }
629 if (state->readingInput && anchor) {
630 const auto operation = (*record)->operation;
631 auto capture = (*record)->capture;
632 auto bookmark = (*capture)(*record, *anchor);
633
634 if (!bookmark) {
635 return finish(std::unexpected(bookmark.error()));
636 }
637
638 record = navigation.lock();
639 if (!record) {
640 return finish(record.error() == TreeError::CLOSED ? std::expected<void, TreeError>{}
641 : std::unexpected(record.error()));
642 }
643 auto live = stillBound();
644 if (!live || !*live || (*record)->operation != operation) {
645 return finish(!live ? std::unexpected(live.error()) : std::expected<void, TreeError>{});
646 }
647
648 auto updated = (*record)->setPosition(std::move(*bookmark), PositionResolution::EXACT, true);
649
650 if (!updated) {
651 return finish(updated);
652 }
653 }
654
655 if (consumed) {
656 state->pendingInput.reset();
657 }
658 state->offset = offset;
659 state->modelRevision = source->frame->dataRevision();
660 if (auto current = (*record)->current.snapshot()) {
661 state->currentRevision = (*current)->revision;
662 }
663 if (auto reading = (*record)->reading.snapshot()) {
664 state->readingRevision = (*reading)->revision;
665 }
666
667 return finish({});
668 };
669 navigation_->bindings.push_back(std::move(binding));
670
671 return {};
672 } catch (const std::bad_alloc &) {
673 return std::unexpected(error(ManagedPhase::BIND, node, TreeError::NO_MEMORY));
674 }
675}
676
677template <class T>
678std::expected<void, TreeError>
679ManagedScene::retryCanonicalRestore(const std::shared_ptr<detail::ManagedNavigationRecord> &record,
680 const std::shared_ptr<detail::ManagedModelSourceOf<T>> &source) {
681 auto history = record->history;
682 auto pending = history ? history->pending : nullptr;
683 if (!pending || !source->frame ||
684 (pending->publication == source->frame->revision() && pending->sourceRevision == source->navigationRevision)) {
685 return {};
686 }
687 const auto frame = *source->frame;
688 const auto operation = record->operation;
689 const auto sequence = record->sequence;
690 const auto sourceRevision = source->navigationRevision;
691 const auto lifetime = std::weak_ptr<const void>(lifetime_);
692 const auto originNode = root_.id();
693
694 struct PreparingRetry {
695 ManagedScene *scene;
696 std::weak_ptr<const void> lifetime;
697 bool active{true};
698
699 ~PreparingRetry() {
700 if (active && !lifetime.expired()) {
701 scene->preparing_ = false;
702 }
703 }
704 } admission{this, lifetime};
705
706 preparing_ = true;
707 std::optional<std::uint64_t> selectedRevision;
708 auto defer = [&](TreeError cause) -> std::expected<void, TreeError> {
709 if (!lifetime.expired() && !record->closed && record->operation == operation && record->sequence == sequence &&
710 record->model.lock() == source && history->pending == pending && !source->retired &&
711 source->navigationRevision == sourceRevision && source->frame &&
712 source->frame->revision() == frame.revision()) {
713 auto selection = record->selection.snapshot();
714 if (!selection || !selectedRevision || (*selection)->revision != *selectedRevision) {
715 return {};
716 }
717 // A failed admission keeps the accepted intent. Only a newer publication
718 // retries it; paint and resize cannot create allocation/worker polling.
719 pending->publication = frame.revision();
720 pending->sourceRevision = sourceRevision;
721 record->frameRevision = frame.revision();
722 preparing_ = false;
723 admission.active = false;
724 (void)reportError(error(ManagedPhase::PREPARE, {}, cause));
725 }
726 return {};
727 };
728 try {
729 auto currentOwner = record->current.lock();
730 auto readingOwner = record->reading.lock();
731 auto selectionOwner = record->selection.lock();
732 auto currentBase = record->current.snapshot();
733 auto readingBase = record->reading.snapshot();
734 auto selectionBase = record->selection.snapshot();
735 if (!currentOwner || !readingOwner || !selectionOwner || !currentBase || !readingBase || !selectionBase) {
736 return std::unexpected(TreeError::CLOSED);
737 }
738 selectedRevision = (*selectionBase)->revision;
739 if (operation == std::numeric_limits<std::uint64_t>::max()) {
740 return defer(TreeError::IDENTITY_EXHAUSTED);
741 }
742 auto channels = pending->channels;
743 channels.current =
744 channels.current && pending->currentRevision == (*currentBase)->revision && pending->sequence == sequence;
745 channels.reading = channels.reading && pending->readingRevision == (*readingBase)->revision;
746 channels.selection = channels.selection && pending->selectionRevision == (*selectionBase)->revision;
747 auto value = pending->value;
748 value.current = record->bookmark;
749 value.currentResolution = (*currentBase)->value.resolution;
750 value.reading = record->readingBookmark;
751 value.readingResolution = (*readingBase)->value.resolution;
752 if (!channels.selection) {
753 value.selection = (*selectionBase)->value;
754 value.selectedPositions.reset();
755 }
756 // Ordinary current/reading reconciliation uses the latest manual intent;
757 // selected-set reconciliation is confined to the still-owned restore intent.
758 const detail::ModelRestoreChannels resolutionChannels{true, true, channels.selection};
759 PositionResolution outcome{};
760 auto resolved = resolveViewCheckpoint<T>(std::move(value), source, history, history->options().bookmarks, outcome,
761 {}, &resolutionChannels);
762 if (!resolved) {
763 return defer(resolved.error());
764 }
765 if (lifetime.expired()) {
766 return {};
767 }
768 auto staged = history->stage(source, 0, *resolved);
769 if (!staged) {
770 return defer(staged.error());
771 }
772 auto logical = [&](const std::optional<ModelBookmark> &bookmark, PositionResolution state) {
773 NavigationPosition result;
774 result.resource = record->resource;
775 result.resolution = state;
776 if (bookmark) {
777 const auto position = bookmark->position();
778 result.kind = position.kind;
779 result.affinity = position.affinity;
780 if (position.kind == PositionKind::ITEM) {
781 result.row = position.row;
782 } else {
783 result.offset = position.offset;
784 }
785 }
786 return result;
787 };
788 auto publication =
789 record->preparePublication(logical(resolved->current, resolved->currentResolution), resolved->selection,
790 logical(resolved->reading, resolved->readingResolution));
791 if (!publication) {
792 return defer(publication.error());
793 }
794 std::shared_ptr<detail::ModelCanonicalRestore> next;
795 if (detail::pendingModelRestoration(*resolved, channels)) {
796 auto allocated = history->canonicalRestore();
797 if (!allocated) {
798 return defer(allocated.error());
799 }
800 next = std::move(*allocated);
801 next->value = *resolved;
802 next->channels = channels;
803 next->publication = frame.revision();
804 next->sourceRevision = sourceRevision;
805 next->sequence = sequence;
806 next->currentRevision = publication->current.next->revision;
807 next->readingRevision = publication->reading.next->revision;
808 next->selectionRevision = publication->selection.next->revision;
809 }
810 if (lifetime.expired() || record->closed || record->operation != operation || record->sequence != sequence ||
811 record->model.lock() != source || history->pending != pending || source->retired || !source->frame ||
812 source->frame->revision() != frame.revision() || source->navigationRevision != sourceRevision ||
813 !history->valid(*staged) || record->current.snapshot() != currentBase ||
814 record->reading.snapshot() != readingBase || record->selection.snapshot() != selectionBase) {
815 return {};
816 }
817 auto valid = record->validatePublication(*publication);
818 if (!valid) {
819 return defer(valid.error());
820 }
821 auto invalidated = record->invalidatePublication(*publication);
822 if (!invalidated) {
823 return defer(invalidated.error());
824 }
825 auto cancellation = std::move(record->cancellation);
826 record->cancellation = std::stop_source(std::nostopstate);
827 auto request = std::move(record->request);
828 record->request.reset();
829 record->bookmark = resolved->current;
830 record->readingBookmark = resolved->reading;
831 history->commit(std::move(*staged));
832 history->pending = std::move(next);
833 record->frameRevision = frame.revision();
834 ++record->operation;
835 detail::ManagedNavigationRecord::installPublication(*publication);
836 for (const auto &binding : navigation_->bindings) {
837 if (binding->context.lock() == record) {
838 binding->installed(&*resolved, &channels);
839 }
840 }
841 const auto notification = detail::ManagedNavigationRecord::publishPublication(*publication);
842 preparing_ = false;
843 admission.active = false;
844 cancellation.request_stop();
845 if (notification && !lifetime.expired()) {
846 ManagedError failure;
847 failure.phase = ManagedPhase::PREPARE;
848 failure.node = originNode;
849 failure.cause = ApplicationError{ApplicationPhase::DISPATCH, *notification};
850 (void)reportError(std::move(failure));
851 }
852 return {};
853 } catch (const std::bad_alloc &) {
854 return defer(TreeError::NO_MEMORY);
855 } catch (...) {
856 return defer(TreeError::CALLBACK_FAILED);
857 }
858}
859
860template <class T>
861std::expected<void, ManagedError> ManagedNavigation::setModel(ManagedModel<T> model, ModelRebindOptions options) const {
862 auto record = lock();
863 if (!record) {
864 return std::unexpected(ManagedScene::error(ManagedPhase::INPUT, {}, record.error()));
865 }
866 if (!(*record)->owner || !(*record)->finite) {
867 return std::unexpected(ManagedScene::error(ManagedPhase::INPUT, {}, TreeError::INVALID_ARGUMENT));
868 }
869 return (*record)->owner->replaceNavigationModel(*record, std::move(model), options);
870}
871
872template <class T> bool ManagedNavigation::model(ManagedModel<T> model, ModelRebindOptions options) const {
873 auto result = setModel(std::move(model), options);
874 if (!result) {
875 if (auto record = lock(); record && (*record)->owner) {
876 (void)(*record)->owner->reportError(result.error());
877 }
878 }
879 return result.has_value();
880}
881
882template <class T>
883std::expected<void, ManagedError>
884ManagedScene::replaceNavigationModel(const std::shared_ptr<detail::ManagedNavigationRecord> &record,
885 ManagedModel<T> model, ModelRebindOptions options, Node<Widget> overrideNode,
886 std::optional<ManagedViewHandler<T>> prepared) {
887 auto allowed = boundary(ManagedPhase::INPUT, root_);
888 if (!allowed) {
889 return allowed;
890 }
891 if (record->closed || record->lifetime.expired()) {
892 return std::unexpected(error(ManagedPhase::INPUT, root_, TreeError::CLOSED));
893 }
894 auto source = model.lock();
895 if (!source || (*source)->retired || !(*source)->model || (*source)->scene != root_.id() || record->closed ||
896 record->scene != root_.id() || !record->finite) {
897 return std::unexpected(error(ManagedPhase::INPUT, root_, !source ? source.error() : TreeError::INVALID_ARGUMENT));
898 }
899 const auto previousModel = record->model.lock();
900 const auto previousSource = std::dynamic_pointer_cast<detail::ManagedModelSourceOf<T>>(previousModel);
901 if (!previousSource) {
902 return std::unexpected(
903 error(ManagedPhase::INPUT, root_, previousModel ? TreeError::INVALID_ARGUMENT : TreeError::CLOSED));
904 }
905 auto editAdmission = record->beforeEditTransition();
906 if (!editAdmission) {
907 return std::unexpected(error(ManagedPhase::INPUT, root_, editAdmission.error()));
908 }
909 if (record->closed || record->lifetime.expired()) {
910 return std::unexpected(error(ManagedPhase::INPUT, root_, TreeError::CLOSED));
911 }
912 const bool sameModel = previousModel == *source;
913 if (sameModel && !prepared && options.restore == ModelRestorePolicy::REMEMBER) {
914 return {};
915 }
916 if (record->operation == std::numeric_limits<std::uint64_t>::max()) {
917 return std::unexpected(error(ManagedPhase::INPUT, root_, TreeError::IDENTITY_EXHAUSTED));
918 }
919 const auto lifetime = std::weak_ptr<const void>(lifetime_);
920 const auto operation = record->operation;
921 const auto sequence = record->sequence;
922 const auto originNode = root_.id();
923
924 struct Admission {
925 ManagedScene *scene;
926 std::weak_ptr<const void> lifetime;
927 bool active{true};
928
929 ~Admission() {
930 if (active && !lifetime.expired()) {
931 scene->preparing_ = false;
932 }
933 }
934 } admission{this, lifetime};
935
936 preparing_ = true;
937 auto fail = [&](TreeError cause) -> std::expected<void, ManagedError> {
938 return std::unexpected(error(ManagedPhase::INPUT, {}, cause));
939 };
940 try {
941 // Count construction also keeps MSVC Debug proxy allocation within this boundary.
942 std::vector<std::shared_ptr<detail::ManagedNavigationBinding>> members(0);
943 std::vector<std::unique_ptr<detail::PreparedModelViewChange>> staged(0);
944 for (const auto &binding : navigation_->bindings) {
945 if (binding->context.lock() == record) {
946 if (binding->options.projection != NavigationProjection::SAME_MODEL || !binding->stage) {
947 return fail(TreeError::INVALID_ARGUMENT);
948 }
949 members.push_back(binding);
950 }
951 }
952 staged.reserve(members.size());
953 auto currentOwner = record->current.lock();
954 auto selectionOwner = record->selection.lock();
955 auto readingOwner = record->reading.lock();
956 if (!currentOwner || !selectionOwner || !readingOwner) {
957 return fail(!currentOwner ? currentOwner.error()
958 : !selectionOwner ? selectionOwner.error()
959 : readingOwner.error());
960 }
961 auto currentBase = record->current.snapshot();
962 auto selectionBase = record->selection.snapshot();
963 auto readingBase = record->reading.snapshot();
964 if (!currentBase || !selectionBase || !readingBase) {
965 return fail(!currentBase ? currentBase.error() : !selectionBase ? selectionBase.error() : readingBase.error());
966 }
967
968 auto history = record->history;
969 if (!history) {
970 auto limits = options.checkpoints.value_or(
971 ModelCheckpointOptions{record->options.maxCheckpointBytes, record->options.bookmarks});
972 auto created = detail::ModelViewHistory::create(lifetime, limits);
973 if (!created) {
974 return fail(created.error());
975 }
976 history = std::move(*created);
977 } else if (options.checkpoints &&
978 (options.checkpoints->maxBytes != history->options().maxBytes ||
979 options.checkpoints->bookmarks.maxBytes != history->options().bookmarks.maxBytes)) {
980 return fail(TreeError::INVALID_ARGUMENT);
981 }
982
983 detail::ModelViewCheckpoint target;
984 const auto navigationRevision = (*source)->navigationRevision;
985 auto pinned = (*source)->pin();
986 if (!pinned || lifetime.expired()) {
987 return fail(!pinned ? pinned.error() : TreeError::CLOSED);
988 }
989 const auto revision = (*source)->frame->revision();
990 std::optional<detail::ModelViewHistoryChange> outgoing;
991 std::optional<detail::ModelViewHistoryChange> destination;
992 std::optional<detail::ModelViewCheckpoint> continuation;
993 PositionResolution resolution = PositionResolution::EMPTY;
994 if (!sameModel || options.restore == ModelRestorePolicy::RESET) {
995 if (!sameModel) {
996 detail::ModelViewCheckpoint value{record->bookmark, (*selectionBase)->value, record->readingBookmark, 0};
997 value.currentResolution = (*currentBase)->value.resolution;
998 value.readingResolution = (*readingBase)->value.resolution;
999 if (auto cached = history->find(previousModel, 0);
1000 cached && cached->value.selection.resource() == value.selection.resource() &&
1001 std::ranges::equal(cached->value.selection.rows(), value.selection.rows())) {
1002 value.selectedPositions = cached->value.selectedPositions;
1003 }
1004 auto captured = captureSelectedPositions(value, previousSource, history, history->options().bookmarks);
1005 if (!captured || lifetime.expired()) {
1006 return fail(!captured ? captured.error() : TreeError::CLOSED);
1007 }
1008 if (record->resource == (*source)->navigationResource) {
1009 continuation = std::move(value);
1010 } else {
1011 auto saved = history->stage(previousModel, 0, std::move(value));
1012 if (!saved) {
1013 return fail(saved.error());
1014 }
1015 outgoing = std::move(*saved);
1016 }
1017 }
1018 if (options.restore == ModelRestorePolicy::REMEMBER) {
1019 if (continuation) {
1020 target = std::move(*continuation);
1021 } else if (auto cached = history->find(*source, 0)) {
1022 target = cached->value;
1023 }
1024 }
1025 if (detail::hasModelRestoreIntent(target)) {
1026 auto resolved =
1027 resolveViewCheckpoint<T>(std::move(target), *source, history, history->options().bookmarks, resolution);
1028 if (!resolved || lifetime.expired()) {
1029 return fail(!resolved ? resolved.error() : TreeError::CLOSED);
1030 }
1031 target = std::move(*resolved);
1032 }
1033 } else {
1034 target = {record->bookmark, (*selectionBase)->value, record->readingBookmark, 0};
1035 resolution = (*currentBase)->value.resolution;
1036 }
1037 auto resource = detail::modelNavigationResource(**source);
1038 if (!resource) {
1039 return fail(resource.error());
1040 }
1041 if (target.selection.rows().empty()) {
1042 target.selection.resource_ = *resource;
1043 target.selection.resolution_ = PositionResolution::EMPTY;
1044 }
1045 auto savedDestination = history->stage(*source, 0, target);
1046 if (!savedDestination) {
1047 return fail(savedDestination.error());
1048 }
1049 destination = std::move(*savedDestination);
1050
1051 // Every view registration uses this capacity; individual stages cannot cause
1052 // a later push_back allocation after another participant has been installed.
1053 std::erase_if((*source)->prepared, [](const auto &registration) {
1054 return registration.expired();
1055 });
1056 (*source)->prepared.reserve((*source)->prepared.size() + members.size());
1057 for (const auto &member : members) {
1058 auto position = target;
1059 if (member->options.readingAnchor && target.reading) {
1060 position.first = target.reading->position().offset;
1061 } else {
1062 position.reading.reset();
1063 }
1064 auto next = member->stage(*source, options, history, &position,
1065 member->node == overrideNode && prepared ? &prepared : nullptr);
1066 if (lifetime.expired()) {
1067 return fail(TreeError::CLOSED);
1068 }
1069 if (!next) {
1070 return std::unexpected(next.error());
1071 }
1072 staged.push_back(std::move(*next));
1073 }
1074 auto logical = [&](const std::optional<ModelBookmark> &bookmark, PositionResolution outcome) {
1075 NavigationPosition value;
1076 value.resource = *resource;
1077 value.resolution = outcome;
1078 if (bookmark) {
1079 const auto position = bookmark->position();
1080 value.kind = position.kind;
1081 value.affinity = position.affinity;
1082 if (position.kind == PositionKind::ITEM) {
1083 value.row = position.row;
1084 } else {
1085 value.offset = position.offset;
1086 }
1087 }
1088 return value;
1089 };
1090 const auto nextCurrent = logical(target.current, target.currentResolution);
1091 auto editTarget = record->beforeEditTransition(&nextCurrent, *source);
1092 if (!editTarget) {
1093 return fail(editTarget.error());
1094 }
1095 if (record->closed || lifetime.expired() || record->operation != operation || record->sequence != sequence) {
1096 return fail(record->closed || lifetime.expired() ? TreeError::CLOSED : TreeError::WOULD_BLOCK);
1097 }
1098 auto publication =
1099 record->preparePublication(nextCurrent, target.selection, logical(target.reading, target.readingResolution));
1100 if (!publication) {
1101 return fail(publication.error());
1102 }
1103 std::shared_ptr<detail::ModelCanonicalRestore> restoredIntent;
1104 if (detail::pendingModelRestoration(target, {})) {
1105 auto created = history->canonicalRestore();
1106 if (!created) {
1107 return fail(created.error());
1108 }
1109 restoredIntent = std::move(*created);
1110 restoredIntent->value = target;
1111 restoredIntent->publication = revision;
1112 restoredIntent->sourceRevision = navigationRevision;
1113 restoredIntent->sequence = sequence;
1114 restoredIntent->currentRevision = publication->current.next->revision;
1115 restoredIntent->readingRevision = publication->reading.next->revision;
1116 restoredIntent->selectionRevision = publication->selection.next->revision;
1117 }
1118
1119 // This is deliberately after every provider/resolver/user staging callout.
1120 if (lifetime.expired() || record->closed || record->operation != operation || record->sequence != sequence ||
1121 record->model.lock() != previousModel || (*source)->retired || !(*source)->frame ||
1122 (*source)->frame->revision() != revision || (*source)->navigationRevision != navigationRevision ||
1123 record->current.snapshot() != currentBase || record->selection.snapshot() != selectionBase ||
1124 record->reading.snapshot() != readingBase || (outgoing && !history->valid(*outgoing)) ||
1125 (destination && !history->valid(*destination))) {
1126 return fail(TreeError::WOULD_BLOCK);
1127 }
1128 for (std::size_t index = 0; index < members.size(); ++index) {
1129 if (!std::ranges::contains(navigation_->bindings, members[index]) || members[index]->context.lock() != record) {
1130 return fail(TreeError::WOULD_BLOCK);
1131 }
1132 auto valid = staged[index]->validate();
1133 if (!valid) {
1134 return fail(valid.error());
1135 }
1136 }
1137 auto valid = record->validatePublication(*publication);
1138 if (!valid) {
1139 return fail(valid.error());
1140 }
1141 for (const auto &next : staged) {
1142 auto invalidated = next->invalidate();
1143 if (!invalidated) {
1144 return fail(invalidated.error());
1145 }
1146 }
1147 auto invalidated = record->invalidatePublication(*publication);
1148 if (!invalidated) {
1149 return fail(invalidated.error());
1150 }
1151
1152 // No callout occurs between validation and the last install. Old consumers,
1153 // requests, snapshots, callback owners and cancellation are retained locally.
1154 for (const auto &next : staged) {
1155 auto installed = next->install();
1156 if (!installed) {
1157 return fail(installed.error());
1158 }
1159 }
1160 auto previousCancellation = std::move(record->cancellation);
1161 record->cancellation = std::stop_source(std::nostopstate);
1162 auto previousRequest = std::move(record->request);
1163 record->request.reset();
1164 record->model = *source;
1165 record->resource = *resource;
1166 record->session = resource->identity;
1167 record->bookmark = std::move(target.current);
1168 record->readingBookmark = std::move(target.reading);
1169 record->changes = (*source)->navigationChanges;
1170 record->frameRevision = revision;
1171 record->history = history;
1172 auto previousRestore = std::move(history->pending);
1173 history->pending = std::move(restoredIntent);
1174 ++record->operation;
1175 if (outgoing) {
1176 history->commit(std::move(*outgoing));
1177 }
1178 if (destination) {
1179 history->commit(std::move(*destination));
1180 }
1181 for (const auto &next : staged) {
1182 next->commitHistory();
1183 }
1184 detail::ManagedNavigationRecord::installPublication(*publication);
1185 for (const auto &member : members) {
1186 member->installed(nullptr, nullptr);
1187 }
1188 const auto notification = detail::ManagedNavigationRecord::publishPublication(*publication);
1189
1190 // Retirement callbacks may now start a newer operation. There are no old
1191 // model/view/property writes after the first retirement callout.
1192 preparing_ = false;
1193 admission.active = false;
1194 previousCancellation.request_stop();
1195 for (const auto &next : staged) {
1196 next->retire();
1197 }
1198 if (notification && !lifetime.expired()) {
1199 ManagedError failure;
1200 failure.phase = ManagedPhase::INPUT;
1201 failure.node = originNode;
1202 failure.cause = ApplicationError{ApplicationPhase::DISPATCH, *notification};
1203 // This receipt belongs to the completed older publication even if a stop
1204 // callback has already installed a newer coherent group.
1205 (void)reportError(std::move(failure));
1206 }
1207 return {};
1208 } catch (const std::bad_alloc &) {
1209 return fail(TreeError::NO_MEMORY);
1210 } catch (const std::length_error &) {
1211 return fail(TreeError::NODE_LIMIT);
1212 } catch (...) {
1213 return fail(TreeError::CALLBACK_FAILED);
1214 }
1215}
1216} // namespace portals
static std::expected< FinitePositionResolver, SourceError > create(ModelResource resource, SourceStamp session, std::shared_ptr< const ModelSnapshot< T > > snapshot, PositionChangeMap changes={})
Definition model_position_finite.hpp:62
Weak UI handle to a model owned by one ManagedScene. Handles may be copied and destroyed on any threa...
Definition managed_model.hpp:120
Weak UI-affine navigation handle owned by an existing scene/model scope. Removing a view does not rem...
Definition managed_navigation.hpp:119
bool model(ManagedModel< T > model, ModelRebindOptions options={}) const
Definition managed_navigation_views.hpp:872
std::expected< void, ManagedError > setModel(ManagedModel< T > model, ModelRebindOptions options={}) const
Definition managed_navigation_views.hpp:861
std::expected< void, ManagedError > bindNavigation(Node< VirtualList< T > > node, ManagedNavigation navigation, NavigationBindingOptions options={})
Definition managed_navigation_views.hpp:257
std::expected< ManagedModel< T >, ManagedError > model(std::shared_ptr< const ModelSnapshot< T > > initial, ModelOptions options={}, ManagedViewHandler< T > prepared={})
Create a scene-owned model and a weak typed UI handle.
Definition managed_views.hpp:65
std::expected< ManagedState< T >, ManagedError > state(T initial, Invalidation kind=Invalidation::PAINT, PropertyOptions options={})
Create UI-owned state with guaranteed dirty-frame recovery of missed notifications.
Definition managed.hpp:655
std::expected< void, ManagedError > id(Node< Widget > node, std::string_view value)
std::expected< ManagedNavigation, ManagedError > navigation(ModelResource resource, SourceStamp session, NavigationOptions options={})
static std::expected< ModelBookmark, SourceError > create(ModelResource resource, ModelPosition position, std::span< const std::byte > metadata={}, BookmarkOptions options={})
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
One UI-owned view with bounded owning row text and one independent model consumer....
Definition virtual_list.hpp:133
One UI-owned table with bounded owning cell text and one independent model consumer....
Definition virtual_table.hpp:154
auto live(ManagedScene &scene, const S &description)
Definition style_static.hpp:1703
Public Portals API.
Definition action.hpp:8
std::expected< void, TreeError > setVirtualListFirst(WidgetTree &tree, Node< VirtualList< T > > node, std::uint64_t first)
Change the integral first row on UI and invalidate paint; prepare before painting again.
Definition virtual_list.hpp:663
@ PRESERVES_ROW_IDS
Caller guarantees identical complete RowIds in the original source domain.
Definition managed_navigation.hpp:104
@ SAME_MODEL
Binding must use the context's original managed model.
Definition managed_navigation.hpp:103
std::expected< void, TreeError > setVirtualTableSelection(WidgetTree &tree, Node< VirtualTable< T > > node, std::optional< RowId > selected)
Set stable selection on UI, clear pending navigation, and invalidate paint.
Definition virtual_table.hpp:788
@ ITEM
Full RowId with a version-qualified ordinal hint.
Definition model_position.hpp:36
std::expected< RowLookup, TreeError > ensureVirtualListVisible(WidgetTree &tree, Node< VirtualList< T > > node, const ModelFrame< T > &frame, RowId id)
Reveal a stable row using a caller-supplied shared pin and the last prepared viewport.
Definition virtual_list.hpp:811
std::expected< RowLookup, TreeError > ensureVirtualTableVisible(WidgetTree &tree, Node< VirtualTable< T > > node, const ModelFrame< T > &frame, RowId id)
Reveal a stable row using a caller-supplied shared pin and the last prepared viewport.
Definition virtual_table.hpp:960
PositionResolution
Successful protocol outcomes; absence of support differs from missing history.
Definition model_position.hpp:123
@ UNSUPPORTED
The provider does not implement the requested kind or identity capability.
Definition model_position.hpp:128
@ NEAREST
The original item was removed; a declared surviving neighbor was selected.
Definition model_position.hpp:125
@ EMPTY
Compatible source is empty and has no current item.
Definition model_position.hpp:126
@ EXACT
The same item or a proven mapped gap/mark is present.
Definition model_position.hpp:124
@ STATE
Create and retain a scene-owned property.
Definition managed_diagnostics.hpp:50
@ BIND
Register a managed callback, binding or presentation adapter.
Definition managed_diagnostics.hpp:51
@ INPUT
Dispatch input or deliver a managed control/property callback.
Definition managed_diagnostics.hpp:54
std::expected< void, TreeError > setVirtualListSelection(WidgetTree &tree, Node< VirtualList< T > > node, std::optional< RowId > selected)
Set stable selection on UI, clear pending navigation, and invalidate paint.
Definition virtual_list.hpp:678
@ FOUND
The index identifies this RowId in the same snapshot.
Definition model.hpp:74
std::expected< void, TreeError > setVirtualTableFirst(WidgetTree &tree, Node< VirtualTable< T > > node, std::uint64_t first)
Change the integral first row on UI and invalidate paint; prepare before painting again.
Definition virtual_table.hpp:773
@ LAYOUT
Layout and painting are required; old arranged geometry becomes invalid.
Definition widget_types.hpp:44
std::function< std::expected< void, TreeError >(const ModelFrame< T > &, const std::optional< ModelRequest< T > > &)> ManagedViewHandler
Owning callback after each successful virtual-view preparation, including layout retries....
Definition managed_model.hpp:25
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
@ CLOSED
The owning tree or source is closed.
Definition widget_types.hpp:31
@ STALE_NODE
The observed node or model consumer is absent or retired.
Definition widget_types.hpp:30
@ WOULD_BLOCK
The current frame/reentry boundary or finite queue/work budget rejects this operation.
Definition widget_types.hpp:32
@ 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
Explicit rebinding policy; omitted history options inherit the session's settings.
Definition managed_navigation.hpp:44
ModelRestorePolicy restore
Default return-to-resource behavior.
Definition managed_navigation.hpp:45
std::optional< ModelCheckpointOptions > checkpoints
Initial session capacity; immutable once history exists.
Definition managed_navigation.hpp:47
Logical resource namespace, distinct from its current delivery session. Reuse an existing SourceStamp...
Definition model_position.hpp:21
static std::expected< ModelResource, SourceError > create()
Independent opt-in view channels; scrolling never changes current by itself.
Definition managed_navigation.hpp:108
bool readingAnchor
Share logical first-row anchors, mapped independently in each projection.
Definition managed_navigation.hpp:111
bool current
Share stable current using the control's existing single-selection policy.
Definition managed_navigation.hpp:110
NavigationProjection projection
Explicit source-domain agreement.
Definition managed_navigation.hpp:109
Positive bounded metadata limits; no source extent or viewport is retained.
Definition managed_navigation.hpp:95
Immutable source namespace; replacement sessions must share their old budget root.
Definition window_source.hpp:27