Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
theme_selector.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/dialog.hpp>
6#include <portals/theme_selection.hpp>
7
8#include <concepts>
9#include <optional>
10#include <span>
11#include <type_traits>
12#include <vector>
13
14namespace portals::ui {
15template <class T> class Description;
16template <class T> class Ref;
17
18namespace detail {
19struct ThemeSelectorTarget;
20struct ThemeSelectorAccess;
21} // namespace detail
22
24enum class ThemeSelectorCloseDisposition {
25 NOT_ATTEMPTED,
26 OPEN,
27 CLOSED,
28 RETIRED
29};
30
36 ~ThemeApplyOutcome() = default;
37 std::string committedId = std::string(0, '\0');
38 ThemeSelectorCloseDisposition closeDisposition{ThemeSelectorCloseDisposition::NOT_ATTEMPTED};
39 std::optional<ManagedError> callbackError;
40 std::optional<ManagedError> closeError;
41};
42
48 TextValue title{"Themes"};
49 TextValue apply{"Apply"};
50 TextValue cancel{"Cancel"};
51 TextValue closeKeepingPreview{"Close (keep preview)"};
52 TextValue emptyStatus{"Choose a theme to preview"};
53 TextValue errorStatus{"Theme action failed; retry or close keeping preview"};
54 TextValue conflictStatus{"Theme changed elsewhere; preview again or close keeping preview"};
55 TextLimits textLimits{4096, 4096, 4096, 8192};
56 std::function<std::expected<std::string, TextResourceError>(std::string_view)>
58 std::optional<std::string> openingShortcut{std::in_place,
59 "Ctrl+K, Ctrl+T"};
60
64 std::function<std::expected<void, ManagedError>(std::string_view)> onCommitted;
65};
66
73 std::vector<ThemeChoice> choices;
75 std::optional<std::string> initialId;
76};
77
83public:
87 std::expected<void, ManagedError> open(std::source_location origin = std::source_location::current()) const;
93 std::expected<void, ManagedError> preview(std::string_view id,
94 std::source_location origin = std::source_location::current()) const;
99 std::expected<void, ManagedError> commit(std::source_location origin = std::source_location::current()) const;
103 std::expected<std::shared_ptr<const ThemeSelectionSnapshot>, ManagedError> snapshot() const;
108 std::expected<void, ManagedError> apply(std::source_location origin = std::source_location::current()) const;
111 std::expected<void, ManagedError> cancel(std::source_location origin = std::source_location::current()) const;
113 std::expected<void, ManagedError>
114 closeKeepingPreview(std::source_location origin = std::source_location::current()) const;
119 std::expected<std::shared_ptr<const ThemeApplyOutcome>, ManagedError> lastApply() const;
120
121private:
122 friend struct detail::ThemeSelectorAccess;
123 std::shared_ptr<detail::ThemeSelectorTarget> target_;
124};
125
131template <> class Ref<ThemeSelectorRef> : public ThemeSelectorRef {
132public:
134 Ref() = default;
135
139 explicit Ref(ThemeSelectorRef reference) noexcept : ThemeSelectorRef(std::move(reference)) {
140 }
141};
142
149Description<Dialog> themeSelector(ThemeSelectorRef reference, ThemeSelectionRef model,
150 ThemeSelectorOptions options = {});
151
161template <std::size_t N>
162 requires(N > 0)
163Description<Dialog> themeSelector(ThemeSelectorRef reference, const ThemeChoice (&choices)[N],
164 ThemeSelectorOptions options = {});
165
173template <class Catalog>
174 requires std::same_as<std::remove_cvref_t<Catalog>, ThemeSelectorCatalog>
175Description<Dialog> themeSelector(ThemeSelectorRef reference, Catalog &&catalog, ThemeSelectorOptions options = {});
176} // namespace portals::ui
177
178namespace portals {
183} // namespace portals
Owning literal bytes or a resource key, measured only at resolution.
Definition text_value.hpp:42
Single-use owning construction recipe; no mounted widget ownership.
Definition ui_description.hpp:48
Ref(ThemeSelectorRef reference) noexcept
Definition theme_selector.hpp:139
Ref()=default
Create the existing cold selector identity; construction may throw std::bad_alloc.
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
Weak UI-affine observation of one scene-owned selector view. Commands are checked only: they never re...
Definition theme_selector.hpp:82
ThemeSelectorRef()
Create a cold identity; allocation may throw before a scene owner exists.
std::expected< void, ManagedError > closeKeepingPreview(std::source_location origin=std::source_location::current()) const
std::expected< void, ManagedError > apply(std::source_location origin=std::source_location::current()) const
std::expected< std::shared_ptr< const ThemeSelectionSnapshot >, ManagedError > snapshot() const
std::expected< void, ManagedError > preview(std::string_view id, std::source_location origin=std::source_location::current()) const
std::expected< void, ManagedError > commit(std::source_location origin=std::source_location::current()) const
std::expected< std::shared_ptr< const ThemeApplyOutcome >, ManagedError > lastApply() const
std::expected< void, ManagedError > open(std::source_location origin=std::source_location::current()) const
std::expected< void, ManagedError > cancel(std::source_location origin=std::source_location::current()) const
Public Portals API.
Definition action.hpp:8
ui::ThemeSelectorRef ThemeSelector
Canonical composite facade type for ui::Ref<ThemeSelector>; exactly the legacy ui::ThemeSelectorRef....
Definition theme_selector.hpp:182
Owning panel geometry and managed input settings, in terminal cells.
Definition dialog.hpp:52
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
Owning limits checked without silently truncating input or clusters.
Definition text.hpp:57
One immutable owning completed Apply result, independent of the view lifetime. Both error slots prese...
Definition theme_selector.hpp:34
std::optional< ManagedError > callbackError
Original optional persistence callback failure.
Definition theme_selector.hpp:39
ThemeSelectorCloseDisposition closeDisposition
Actual final state.
Definition theme_selector.hpp:38
~ThemeApplyOutcome()=default
Retain fallible owning ID copies with checked standard-library configurations.
std::string committedId
Successfully committed application catalog ID.
Definition theme_selector.hpp:37
std::optional< ManagedError > closeError
Independent full view-close failure; never replaces callback cleanup.
Definition theme_selector.hpp:40
Finite normalization budgets and optional first-preview layer admission.
Definition theme_selection.hpp:77
Advanced owning catalog settings for a selector with its scene-owned default model....
Definition theme_selector.hpp:70
~ThemeSelectorCatalog()=default
Keep owning input transfers fallible with checked standard-library containers.
std::vector< ThemeChoice > choices
Copied synchronous catalog, normalized once before creating the view.
Definition theme_selector.hpp:73
ThemeSelectionOptions selection
Existing normalization budgets, resolver and first-preview layers.
Definition theme_selector.hpp:74
std::optional< std::string > initialId
Optional startup preview+commit after scene configuration; no callback.
Definition theme_selector.hpp:75
Owning selector captions, established dialog settings and optional application delivery.
Definition theme_selector.hpp:44
TextValue title
Owning dialog title, resolved during mounting.
Definition theme_selector.hpp:48
DialogOptions dialog
Existing modal geometry defaults; eager Escape is disabled by this composition.
Definition theme_selector.hpp:47
TextValue conflictStatus
Superseded status.
Definition theme_selector.hpp:54
TextValue cancel
Owning checked-restoration caption.
Definition theme_selector.hpp:50
std::function< std::expected< std::string, TextResourceError >(std::string_view)> textResolver
Local mount resolver.
Definition theme_selector.hpp:57
TextValue emptyStatus
No currently selected active choice.
Definition theme_selector.hpp:52
TextValue apply
Owning Apply caption.
Definition theme_selector.hpp:49
std::function< std::expected< void, ManagedError >(std::string_view)> onCommitted
Optional synchronous UI callback, invoked once after a successful guarded commit. The ID borrow expir...
Definition theme_selector.hpp:64
std::optional< std::string > openingShortcut
Canonical text; absent disables binding.
Definition theme_selector.hpp:58
TextValue errorStatus
Bounded recoverable status.
Definition theme_selector.hpp:53
TextValue closeKeepingPreview
Explicit hide-only recovery action.
Definition theme_selector.hpp:51
TextLimits textLimits
Positive validation limits for each caption/status.
Definition theme_selector.hpp:55
~ThemeSelectorOptions()=default
Keep owning option/callback transfers fallible.