Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
managed_navigation.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <concepts>
6#include <optional>
7#include <portals/model_position.hpp>
8#include <thread>
9#include <vector>
10
11namespace portals {
12class ManagedScene;
13struct ManagedError;
14template <class T> class ManagedModel;
15template <std::equality_comparable T> class ManagedSource;
16
18namespace ui::detail {
19struct Access;
20struct EditAccess;
21} // namespace ui::detail
22
24
25namespace detail {
26struct ManagedNavigationRecord;
27struct EditNavigationParticipant;
28struct ManagedNavigationRegistry;
29} // namespace detail
30
36
39 std::size_t maxBytes{256 * 1024};
41};
42
49
66
69public:
70 NavigationSelection() = default;
75 std::span<const RowId> rows() const noexcept;
77 ModelResource resource() const noexcept;
83 bool operator==(const NavigationSelection &other) const noexcept;
84
85private:
86 friend class ManagedNavigation;
87 friend class ManagedScene;
88 friend struct detail::ManagedNavigationRecord;
89 ModelResource resource_;
91 std::shared_ptr<const std::vector<RowId>> rows_;
92};
93
96 std::size_t maxSelectedRows{1024};
98 std::size_t maxCheckpointBytes{256 * 1024};
99};
100
106
113
120public:
121 ManagedNavigation() = default;
127 template <class T>
128 std::expected<void, ManagedError> setModel(ManagedModel<T> model, ModelRebindOptions options = {}) const;
133 template <class T> bool model(ManagedModel<T> model, ModelRebindOptions options = {}) const;
135 std::expected<ManagedSource<NavigationPosition>, TreeError> current() const;
137 std::expected<ManagedSource<NavigationSelection>, TreeError> selection() const;
139 std::expected<ManagedSource<NavigationPosition>, TreeError> readingAnchor() const;
141 std::expected<std::optional<ModelBookmark>, TreeError> bookmark() const;
143 std::expected<std::optional<ModelBookmark>, TreeError> readingBookmark() const;
147 std::expected<void, TreeError> navigate(RowId id) const;
151 std::expected<void, TreeError> setCurrent(ModelBookmark bookmark) const;
153 std::expected<void, TreeError> clearCurrent() const;
157 std::expected<void, TreeError> setSelection(std::span<const RowId> rows) const;
161 std::expected<void, TreeError> setReadingAnchor(ModelBookmark bookmark) const;
163 std::expected<void, TreeError> clearReadingAnchor() const;
167 std::expected<void, TreeError> setChangeMap(PositionChangeMap changes) const;
172 std::expected<PositionRequest, TreeError> beginResolve(std::uint64_t revision) const;
176 std::expected<bool, TreeError> applyReply(const PositionReply &reply) const;
178 std::expected<std::stop_token, TreeError> stopToken() const;
179
180private:
181 friend class ManagedScene;
182 friend struct ui::detail::Access;
183 friend struct ui::detail::EditAccess;
184 std::expected<std::shared_ptr<detail::ManagedNavigationRecord>, TreeError> lock() const;
185 std::weak_ptr<detail::ManagedNavigationRecord> record_;
186 std::thread::id owner_{};
187};
188} // namespace portals
Weak UI handle to a model owned by one ManagedScene. Handles may be copied and destroyed on any threa...
Definition managed_model.hpp:120
std::expected< ManagedSource< NavigationPosition >, TreeError > current() const
std::expected< void, TreeError > clearCurrent() const
bool model(ManagedModel< T > model, ModelRebindOptions options={}) const
Definition managed_navigation_views.hpp:872
std::expected< std::optional< ModelBookmark >, TreeError > bookmark() const
std::expected< ManagedSource< NavigationPosition >, TreeError > readingAnchor() const
std::expected< void, TreeError > setSelection(std::span< const RowId > rows) const
std::expected< void, TreeError > setReadingAnchor(ModelBookmark bookmark) const
std::expected< void, TreeError > setCurrent(ModelBookmark bookmark) const
std::expected< void, TreeError > clearReadingAnchor() const
std::expected< std::optional< ModelBookmark >, TreeError > readingBookmark() const
std::expected< void, TreeError > navigate(RowId id) const
std::expected< bool, TreeError > applyReply(const PositionReply &reply) const
std::expected< void, ManagedError > setModel(ManagedModel< T > model, ModelRebindOptions options={}) const
Definition managed_navigation_views.hpp:861
ManagedNavigation()=default
Empty handle; operations return CLOSED.
std::expected< void, TreeError > setChangeMap(PositionChangeMap changes) const
std::expected< PositionRequest, TreeError > beginResolve(std::uint64_t revision) const
std::expected< ManagedSource< NavigationSelection >, TreeError > selection() const
std::expected< std::stop_token, TreeError > stopToken() const
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Read-only weak scene-owned derived value; no writable alias or subscription escapes.
Definition managed.hpp:484
Copyable bookmark owning metadata only; never retains model, snapshot, view or page....
Definition model_position.hpp:66
std::span< const RowId > rows() const noexcept
ModelResource resource() const noexcept
NavigationSelection()=default
Empty selection, without allocating.
PositionResolution resolution() const noexcept
Immutable bounded provider proof between two revisions of a finite order. The provider must report al...
Definition model_position.hpp:224
Public Portals API.
Definition action.hpp:8
PositionAffinity
Preferred surviving side when a position is deleted or text is inserted beside a mark.
Definition model_position.hpp:42
@ FORWARD
Prefer the following item; an end boundary falls back to the preceding item.
Definition model_position.hpp:43
NavigationProjection
Explicit projection-domain agreement; absence from a projection never proves deletion.
Definition managed_navigation.hpp:102
@ 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
PositionKind
Position interpretation; a row, a gap, and a text mark are not interchangeable.
Definition model_position.hpp:35
@ ITEM
Full RowId with a version-qualified ordinal hint.
Definition model_position.hpp:36
PositionResolution
Successful protocol outcomes; absence of support differs from missing history.
Definition model_position.hpp:123
@ EMPTY
Compatible source is empty and has no current item.
Definition model_position.hpp:126
ModelRestorePolicy
Remember a resource position by default; RESET explicitly selects its initial policy.
Definition managed_navigation.hpp:32
@ REMEMBER
Restore this navigation session's saved resource position.
Definition managed_navigation.hpp:33
@ RESET
Forget the target checkpoint and use its initial position/selection.
Definition managed_navigation.hpp:34
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
Checked bookmark capacity, independent of logical source length.
Definition model_position.hpp:57
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
Bounded history options, independent of model row count.
Definition managed_navigation.hpp:38
std::size_t maxBytes
Aggregate entry/selection/bookmark metadata credit.
Definition managed_navigation.hpp:39
BookmarkOptions bookmarks
Existing 4096-byte per-bookmark default.
Definition managed_navigation.hpp:40
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
bool retainPreparedOverride
Low-level opt-in to retaining a previous view callback across models.
Definition managed_navigation.hpp:46
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
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
BookmarkOptions bookmarks
Maximum owning metadata for each captured position.
Definition managed_navigation.hpp:97
std::size_t maxSelectedRows
Maximum explicit selected set, independent of current/focus.
Definition managed_navigation.hpp:96
std::size_t maxCheckpointBytes
Aggregate remembered resource metadata for this context.
Definition managed_navigation.hpp:98
Published logical position, independent of provider revisions and screen coordinates....
Definition managed_navigation.hpp:54
bool operator==(const NavigationPosition &other) const noexcept=default
ModelResource resource
Logical source domain, including compatible-history lineage.
Definition managed_navigation.hpp:55
std::uint64_t offset
Logical gap/text coordinate; zero for ITEM.
Definition managed_navigation.hpp:58
std::optional< RowId > row
Current item; empty for no-current or non-item positions.
Definition managed_navigation.hpp:57
PositionKind kind
Provider position kind.
Definition managed_navigation.hpp:56
PositionAffinity affinity
Explicit deletion/insertion side.
Definition managed_navigation.hpp:59
PositionResolution resolution
Last declared resolution outcome.
Definition managed_navigation.hpp:60
Owning resolution receipt; meaningful only for its matching live request.
Definition model_position.hpp:142
Provider-assigned row identity, independent of position; increment generation on reuse.
Definition row_id.hpp:9
Internal bridge for checked access to managed scene and recipe state.
Definition ui_recipe_access.hpp:28