5#include <portals/managed_diagnostics.hpp>
6#include <portals/style.hpp>
7#include <portals/text_value.hpp>
9#include <initializer_list>
10#include <source_location>
17struct ThemeSelectionRecord;
24struct ThemeSelectionTarget;
25struct ThemeSelectionAccess;
26struct ThemeSelectorAccess;
27struct ThemeSelectionDescription;
28struct PreparedThemeAccess;
32enum class ThemeSelectionStatus {
57 std::vector<std::shared_ptr<const ThemeChoiceData>>
choices =
58 std::vector<std::shared_ptr<const ThemeChoiceData>>(0);
67 std::shared_ptr<const ThemeCatalog>
catalog;
68 ThemeSelectionStatus
status{ThemeSelectionStatus::IDLE};
86 std::function<std::expected<std::string, TextResourceError>(std::string_view)>
textResolver;
87 std::optional<StyleLayerOptions>
layers;
103 template <
class Factory>
104 requires std::copy_constructible<Factory> && std::invocable<Factory &> &&
105 (std::same_as<std::invoke_result_t<Factory &>,
StyleSheet> ||
106 std::same_as<std::invoke_result_t<Factory &>, std::expected<StyleSheet, StyleError>>)
108 : id_(id), label_(std::move(label)), description_(std::move(description)),
110 return std::invoke(factory);
118 template <
class Factory>
119 requires std::copy_constructible<Factory> && std::invocable<Factory &> &&
120 (std::same_as<std::invoke_result_t<Factory &>, StyleSheet> ||
121 std::same_as<std::invoke_result_t<Factory &>, std::expected<StyleSheet, StyleError>>)
122 ThemeChoice(std::string_view
id, std::string_view label, Factory factory, std::optional<TextValue> description = {})
131 friend struct detail::PreparedThemeAccess;
133 struct PreparedThemeTag {};
143 template <
class Factory>
144 requires std::copy_constructible<Factory> && std::invocable<Factory &, std::stop_token> &&
145 (std::same_as<std::invoke_result_t<Factory &, std::stop_token>,
StyleSheet> ||
146 std::same_as<std::invoke_result_t<Factory &, std::stop_token>, std::expected<StyleSheet, StyleError>>)
148 std::optional<TextValue> description = {})
149 : id_(id), label_(std::move(label)), description_(std::move(description)),
150 preparedFactory_(std::make_shared<PreparedFactory>(
151 [factory = std::move(factory)](std::stop_token stop) mutable -> std::expected<
StyleSheet,
StyleError> {
152 return std::invoke(factory, stop);
156 using PreparedFactory = std::function<std::expected<StyleSheet, StyleError>(std::stop_token)>;
159 std::optional<TextValue> description_;
160 std::function<std::expected<StyleSheet, StyleError>()> factory_;
161 std::shared_ptr<const PreparedFactory> preparedFactory_;
166struct PreparedThemeAccess {
167 template <
class Factory>
168 static ThemeChoice make(std::string_view
id, TextValue label, Factory factory, std::optional<TextValue> description) {
169 return ThemeChoice(ThemeChoice::PreparedThemeTag{},
id, std::move(label), std::move(factory),
170 std::move(description));
193template <
class Factory>
194 requires std::copy_constructible<Factory> && std::invocable<Factory &, std::stop_token> &&
195 (std::same_as<std::invoke_result_t<Factory &, std::stop_token>,
StyleSheet> ||
196 std::same_as<std::invoke_result_t<Factory &, std::stop_token>, std::expected<StyleSheet, StyleError>>)
197ThemeChoice preparedTheme(std::string_view
id,
TextValue label, Factory factory,
198 std::optional<TextValue> description = {}) {
199 return detail::PreparedThemeAccess::make(
id, std::move(label), std::move(factory), std::move(description));
208template <
class Factory>
209 requires std::copy_constructible<Factory> && std::invocable<Factory &, std::stop_token> &&
210 (std::same_as<std::invoke_result_t<Factory &, std::stop_token>,
StyleSheet> ||
211 std::same_as<std::invoke_result_t<Factory &, std::stop_token>, std::expected<StyleSheet, StyleError>>)
212ThemeChoice preparedTheme(std::string_view
id, std::string_view label, Factory factory,
213 std::optional<TextValue> description = {}) {
214 return preparedTheme(
id,
TextValue(label), std::move(factory), std::move(description));
236 std::expected<void, ManagedError>
preview(std::string_view
id,
237 std::source_location origin = std::source_location::current())
const;
243 std::expected<void, ManagedError>
commit(std::source_location origin = std::source_location::current())
const;
248 std::expected<void, ManagedError>
cancel(std::source_location origin = std::source_location::current())
const;
256 friend struct detail::ThemeSelectionAccess;
257 friend struct detail::ThemeSelectorAccess;
258 std::shared_ptr<detail::ThemeSelectionTarget> target_;
273 std::source_location origin = std::source_location::current());
284 std::shared_ptr<const detail::ThemeSelectionDescription> description_;
285 std::source_location origin_;
295 std::source_location origin = std::source_location::current());
Owning validated UTF-8 and immutable extended grapheme measurements.
Definition text.hpp:145
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Owning literal bytes or a resource key, measured only at resolution.
Definition text_value.hpp:42
constexpr TextValue(const TextValue &other)=default
Copy expression bytes and kind into independent storage.
Single-use lazy owner of one Application and ManagedScene; no second runtime. Construct and operate o...
Definition ui_scene.hpp:253
Owning catalog input; legacy factories run synchronously once per explicit preview attempt on UI....
Definition theme_selection.hpp:95
ThemeChoice(std::string_view id, std::string_view label, Factory factory, std::optional< TextValue > description={})
Definition theme_selection.hpp:122
ThemeChoice(std::string_view id, TextValue label, Factory factory, std::optional< TextValue > description={})
Definition theme_selection.hpp:107
~ThemeChoice()=default
Retain fallible ordinary copies of the owning catalog input.
Weak UI-affine observation of the one scene-owned catalog/model. Copying/destroying observations neve...
Definition theme_selection.hpp:224
std::expected< void, ManagedError > preview(std::string_view id, std::source_location origin=std::source_location::current()) const
std::expected< void, ManagedError > cancel(std::source_location origin=std::source_location::current()) const
ThemeSelectionRef()
Construct a cold observation on the UI thread; allocation may throw before an owner exists.
std::expected< std::shared_ptr< const ThemeSelectionSnapshot >, ManagedError > snapshot() const
std::expected< void, ManagedError > commit(std::source_location origin=std::source_location::current()) const
Owning deferred scene configuration; setup publishes the observation only after normalization succeed...
Definition theme_selection.hpp:265
friend Scene operator|(Scene &&input, const ThemeSelectionStage &stage)
ThemeSelectionStage(ThemeSelectionRef reference, std::initializer_list< ThemeChoice > catalog, ThemeSelectionOptions options={}, std::source_location origin=std::source_location::current())
friend Scene & operator|(Scene &owner, const ThemeSelectionStage &stage)
consteval auto id(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:865
Public Portals API.
Definition action.hpp:8
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
Allocation-free error; message borrows a static string literal.
Definition style.hpp:307
Owned immutable-at-use rules; constructing typed values may allocate and throw.
Definition style.hpp:233
Owning limits checked without silently truncating input or clusters.
Definition text.hpp:57
Fixed owning metadata shared by independent snapshots.
Definition theme_selection.hpp:54
std::vector< std::shared_ptr< const ThemeChoiceData > > choices
Ordered metadata; no factories or callbacks.
Definition theme_selection.hpp:57
~ThemeCatalog()=default
Keep checked vector transfers fallible.
GraphemeText label
Resolved display label under the receiving scene width policy.
Definition theme_selection.hpp:49
std::optional< GraphemeText > description
Optional resolved explanation, independently owned.
Definition theme_selection.hpp:50
ThemeChoiceData(std::string_view id, const GraphemeText &label)
Definition theme_selection.hpp:43
std::string id
Unique application catalog ID, never an engine token.
Definition theme_selection.hpp:48
~ThemeChoiceData()=default
Keep owning string/text transfers fallible with the checked standard library.
Finite normalization budgets and optional first-preview layer admission.
Definition theme_selection.hpp:77
std::size_t maxIdBytes
Positive UTF-8 byte cap for each nonempty unique ID.
Definition theme_selection.hpp:81
std::optional< StyleLayerOptions > layers
Absent preserves established budgets or uses engine defaults.
Definition theme_selection.hpp:87
~ThemeSelectionOptions()=default
Keep owning resolver copies fallible.
std::size_t maxChoices
Positive maximum number of catalog entries.
Definition theme_selection.hpp:80
TextLimits textLimits
Positive per-value validation limits beneath byte caps.
Definition theme_selection.hpp:85
std::size_t maxTextBytes
Positive aggregate logical ID/label/description byte cap.
Definition theme_selection.hpp:84
std::size_t maxLabelBytes
Positive resolved label byte cap.
Definition theme_selection.hpp:82
std::size_t maxDescriptionBytes
Positive resolved description byte cap.
Definition theme_selection.hpp:83
std::function< std::expected< std::string, TextResourceError >(std::string_view)> textResolver
Local UI resolver.
Definition theme_selection.hpp:86
Owning point-in-time read model; IDs do not claim the identity of an external theme....
Definition theme_selection.hpp:64
std::optional< std::string > lastCommittedId
Historical successful application choice; absent initially.
Definition theme_selection.hpp:70
ThemeSelectionStatus status
Current preview authority status.
Definition theme_selection.hpp:68
std::optional< std::string > previewedId
Installed choice when ACTIVE; historical choice when SUPERSEDED.
Definition theme_selection.hpp:69
std::shared_ptr< const ThemeCatalog > catalog
Fixed normalized catalog, usable after scene shutdown.
Definition theme_selection.hpp:67
std::optional< ManagedError > preparationError
Exact latest preparation/install failure; absent on success.
Definition theme_selection.hpp:73
bool preparing
Current prepared intent is waiting for admission, work or UI delivery.
Definition theme_selection.hpp:72
std::optional< std::string > requestedId
Latest explicit prepared intent, independent of the installed preview.
Definition theme_selection.hpp:71
~ThemeSelectionSnapshot()=default
Keep owning ID transfers fallible.