Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
data_presentation.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4#include <array>
5#include <portals/controls.hpp>
6#include <portals/model.hpp>
7#include <portals/text_value.hpp>
8
9namespace portals {
19
23 std::uint64_t generation{1};
25 constexpr bool operator==(const DataPresentation &other) const = default;
26};
27
30 bool prepared{};
32 std::uint64_t rowCount{};
33 std::uint64_t dataRevision{};
35};
36
38constexpr std::expected<DataPhase, TreeError> dataPhase(DataRangeStatus status) {
39 if (status.state != RangeState::PENDING && status.state != RangeState::READY && status.state != RangeState::FAILED) {
40 return std::unexpected(TreeError::INVALID_ARGUMENT);
41 }
42 if (!status.prepared) {
43 return DataPhase::LOADING;
44 }
45 if (status.requestPending) {
47 }
48 if (status.state == RangeState::FAILED) {
49 return DataPhase::FAILED;
50 }
51 if (!status.rowCount) {
52 return DataPhase::EMPTY;
53 }
55}
56
59constexpr bool isDataPending(DataPhase phase) noexcept {
60 return phase == DataPhase::LOADING || phase == DataPhase::REFRESHING;
61}
62
67
70 TextValue loading{"Loading..."};
71 TextValue empty{"No data"};
72 TextValue error{"Unable to load data"};
73 TextValue offline{"Offline"};
74 TextValue refreshing{"Refreshing..."};
75 TextValue retry{"Retry"};
76};
77
81 ~DataStateConfig() = default; // Keep checked MSVC owning expression transfers fallible.
82 bool showStatus{true};
83 std::int32_t statusRows{1};
88 std::function<std::expected<std::string, TextResourceError>(std::string_view)>
93 std::function<std::expected<void, TreeError>()> retry;
94};
95
96namespace detail {
97struct DataStateRecord;
98struct DataStateOwner;
99} // namespace detail
100
102class DataStateView : public Column {
103public:
105 explicit DataStateView(SizePolicy policy = DEFAULT_VIEWPORT_POLICY) : Column({}, policy) {
106 }
107
110 return presentation_;
111 }
112
113private:
114 friend class ManagedScene;
115 friend std::expected<void, TreeError> setDataStateView(WidgetTree &, Node<DataStateView>, DataPresentation);
116 std::weak_ptr<detail::DataStateRecord> record_;
117 DataPresentation presentation_;
118};
119
125std::expected<void, TreeError> setDataStateView(WidgetTree &tree, Node<DataStateView> node, DataPresentation value);
126} // namespace portals
Column(LinearOptions options={}, SizePolicy policy={})
Own settings and policies.
DataPresentation presentation() const noexcept
Definition data_presentation.hpp:109
DataStateView(SizePolicy policy=DEFAULT_VIEWPORT_POLICY)
Definition data_presentation.hpp:105
friend std::expected< void, TreeError > setDataStateView(WidgetTree &, Node< DataStateView >, DataPresentation)
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Owning literal bytes or a resource key, measured only at resolution.
Definition text_value.hpp:42
Exclusive parent/child ownership on Scheduler's UI thread. Scheduler must outlive this object....
Definition widget.hpp:179
Public Portals API.
Definition action.hpp:8
std::expected< void, TreeError > setDataStateView(WidgetTree &tree, Node< DataStateView > node, DataPresentation value)
constexpr bool isDataPending(DataPhase phase) noexcept
Definition data_presentation.hpp:59
DataPhase
Presentation facts; offline is explicit domain information, never inferred from an error string.
Definition data_presentation.hpp:11
@ READY
Successful nonempty content; the reserved status strip is blank.
Definition data_presentation.hpp:12
@ OFFLINE
Explicit provider connectivity state, never inferred by the control.
Definition data_presentation.hpp:16
@ REFRESHING
Pending work with provider-permitted last-good content still visible.
Definition data_presentation.hpp:17
@ FAILED
Domain failure; independent technical errors retain their typed cause.
Definition data_presentation.hpp:15
@ EMPTY
Successful content has zero logical rows.
Definition data_presentation.hpp:14
@ LOADING
Initial or viewport request is pending.
Definition data_presentation.hpp:13
DataContentPolicy
Explicit content policy; automatic range wrappers always keep their request-owning body live.
Definition data_presentation.hpp:63
@ REPLACE
Explicit mode only: hide the independently owned body outside READY/REFRESHING.
Definition data_presentation.hpp:65
@ KEEP_BODY
Keep the body visible and prepared in every phase.
Definition data_presentation.hpp:64
@ FAILED
The coroutine returned an error or threw.
Definition async.hpp:46
RangeState
Observable asynchronous range readiness.
Definition model.hpp:45
@ READY
Exactly the requested immutable rows are available.
Definition model.hpp:47
@ FAILED
Provider failure is represented by snapshot-owned text and no rows.
Definition model.hpp:48
@ PENDING
Data is not ready; reading must not block or start work.
Definition model.hpp:46
constexpr SizePolicy DEFAULT_VIEWPORT_POLICY
A bounded data viewport fills both axes without requesting the whole model extent.
Definition layout.hpp:53
std::uint64_t SchedulerTime
Monotonic milliseconds; the clock must not move backwards.
Definition scheduler.hpp:18
constexpr std::expected< DataPhase, TreeError > dataPhase(DataRangeStatus status)
Definition data_presentation.hpp:38
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
Owning paint values; no theme engine or behavior is encoded here.
Definition controls.hpp:24
Owning scalar state of one immutable presentation producer.
Definition data_presentation.hpp:21
constexpr bool operator==(const DataPresentation &other) const =default
std::uint64_t generation
Nonzero producer generation; older values are ignored, never wrapped.
Definition data_presentation.hpp:23
DataPhase phase
Requested presentation; technical errors are separate.
Definition data_presentation.hpp:22
Owning facts from the same successful virtual-view preparation, without another model read.
Definition data_presentation.hpp:29
std::uint64_t dataRevision
Provider revision; zero remains valid under the existing model contract.
Definition data_presentation.hpp:33
bool prepared
False before preparation or after hidden preparation.
Definition data_presentation.hpp:30
std::uint64_t rowCount
Logical model count; zero denotes a known empty model.
Definition data_presentation.hpp:32
RangeState state
Readiness of this prepared range, not the entire model.
Definition data_presentation.hpp:31
bool requestPending
This view still owns current request work; queue acceptance is not UI completion.
Definition data_presentation.hpp:34
Construction-only settings for retained data presentation.
Definition data_presentation.hpp:79
SchedulerTime spinnerInterval
Positive monotonic milliseconds between steps; no catch-up burst.
Definition data_presentation.hpp:86
DataStateLabels labels
Owning expressions, validated only when the strip is used.
Definition data_presentation.hpp:87
ControlStyle retryStyle
Manual retry appearance beneath theme resolution.
Definition data_presentation.hpp:91
~DataStateConfig()=default
Release owning construction settings.
std::function< std::expected< void, TreeError >()> retry
Optional owning explicit action; never starts implicitly.
Definition data_presentation.hpp:93
DataContentPolicy contentPolicy
REPLACE requires explicit independently owned work.
Definition data_presentation.hpp:84
bool showStatus
Mount a stable status strip; false creates no timer, labels or retry button.
Definition data_presentation.hpp:82
std::int32_t statusRows
Positive fixed strip height in terminal rows, including READY.
Definition data_presentation.hpp:83
std::function< std::expected< std::string, TextResourceError >(std::string_view)> resolver
Owning mount-time i18n adapter; no automatic locale subscription.
Definition data_presentation.hpp:89
SizePolicy policy
Root layout constraints, validated by the existing solver.
Definition data_presentation.hpp:92
ControlStyle messageStyle
Manual message/indicator appearance beneath theme resolution.
Definition data_presentation.hpp:90
Owning message expressions resolved once under the receiving scene width policy.
Definition data_presentation.hpp:69
TextValue refreshing
Current or explicitly permitted last-good data remains visible.
Definition data_presentation.hpp:74
TextValue loading
Message while initial/range work is pending.
Definition data_presentation.hpp:70
TextValue empty
Successful empty model message.
Definition data_presentation.hpp:71
TextValue retry
Caption of the optional explicit retry action.
Definition data_presentation.hpp:75
TextValue offline
Explicit domain connectivity message.
Definition data_presentation.hpp:73
TextValue error
Domain failure message; technical diagnostics are separate.
Definition data_presentation.hpp:72
Owning independent policies for width and height.
Definition layout.hpp:35