Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
ui_scene.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/detail/move_only_function.hpp>
6#include <portals/detail/quit_command.hpp>
7#include <portals/detail/setup_failure.hpp>
8#include <portals/managed.hpp>
9#include <portals/ui_action.hpp>
10#include <portals/ui_app.hpp>
11#include <portals/ui_control_context.hpp>
12#include <portals/ui_ref.hpp>
13
14namespace portals::ui {
15
25
28 std::optional<ManagedError> failure;
29 std::source_location origin{};
30 std::size_t retainedErrors{};
31 std::size_t droppedErrors{};
32 std::optional<CommandLineError> commandLineFailure{};
33};
34
41using SceneReportHandler = std::function<void(const SceneReport &)>;
42
48void reportToStderr(const SceneReport &report) noexcept;
49
50namespace detail {
54template <class Callback>
55concept SceneConfiguration = requires(Callback &callback, ManagedScene &scene) {
56 { callback(scene) } -> std::same_as<void>;
57} || requires(Callback &callback, ManagedScene &scene) {
58 { callback(scene) } -> std::same_as<std::expected<void, ManagedError>>;
59} || (!std::invocable<Callback &, ManagedScene &> &&
60 (requires(Callback &callback, ManagedScene &scene, Application &application) {
61 { callback(scene, application) } -> std::same_as<void>;
62 } || requires(Callback &callback, ManagedScene &scene, Application &application) {
63 { callback(scene, application) } -> std::same_as<std::expected<void, ManagedError>>;
64 }));
65
69template <class Callback>
70concept SceneStop = requires(Callback &callback) {
71 { callback() } -> std::same_as<void>;
72} || requires(Callback &callback) {
73 { callback() } -> std::same_as<std::expected<void, ManagedError>>;
74};
75
76struct SceneAccess;
77struct SceneAnchor;
78struct LiveBinding;
79struct LiveFactory;
80} // namespace detail
81
82template <class T> class Ref;
83class DynamicRef;
84class StyleStage;
85struct StyleOptions;
86
90class SceneRef {
91public:
93 SceneRef() = default;
94
99 std::expected<void, ManagedError> quit(std::source_location origin = std::source_location::current()) const;
100
101private:
102 friend class Scene;
103 friend struct detail::SceneAccess;
104 friend struct QuitAction;
105
106 SceneRef(std::weak_ptr<detail::SceneAnchor> anchor, std::thread::id owner)
107 : anchor_(std::move(anchor)), owner_(owner) {
108 }
109
110 void report(const ManagedError &failure, std::source_location origin) const;
111 std::weak_ptr<detail::SceneAnchor> anchor_;
112 std::thread::id owner_{};
113};
114
118 std::source_location origin{};
119
121 void operator()() const {
122 auto result = scene.quit(origin);
123
124 if (!result) {
125 scene.report(result.error(), origin);
126 }
127 }
128};
129
134inline QuitAction quit(SceneRef scene, std::source_location origin = std::source_location::current()) {
135 return {std::move(scene), origin};
136}
137
142void quit(std::source_location origin = std::source_location::current());
143
147 SceneReportHandler report{};
149 std::stop_token stop{};
150};
151
152namespace detail {
155 std::optional<ManagedError> failure;
156 std::size_t droppedErrors{};
157
161 std::size_t attach(ManagedError &primary) const noexcept;
162};
163
166public:
168 explicit FactoryCleanupScope(FactoryCleanup *collector = nullptr) noexcept;
170 FactoryCleanupScope &operator=(const FactoryCleanupScope &) = delete;
172
174 static void retain(const ManagedError &failure) noexcept;
175
177 static bool capturing() noexcept;
178
179private:
180 FactoryCleanup *previous_;
181 static thread_local FactoryCleanup *current_;
182};
183
188void deliverFactoryReport(const SceneReportHandler &sink, const SceneReport &report) noexcept;
189
196SceneReport factoryFailureReport(ManagedError failure, std::source_location origin,
197 const FactoryCleanup &cleanup = {}) noexcept;
198
205void reportFactoryFailure(const SceneReportHandler &sink, ManagedError failure, std::source_location origin,
206 const FactoryCleanup &cleanup = {}) noexcept;
207
210 const std::thread::id owner = std::this_thread::get_id();
211 void *state{};
213 std::expected<void, ManagedError> (*quit)(void *, std::source_location){};
215 std::expected<void, ManagedError> (*lookup)(void *, const LookupSource &, LookupPublisher){};
216 std::shared_ptr<RefTarget> events = std::make_shared<RefTarget>();
217};
218
221 virtual ~LiveBinding() = default;
222
228 virtual std::expected<bool, ManagedError> attach(ManagedScene &scene, const std::shared_ptr<SceneAnchor> &anchor) = 0;
229};
230
235 virtual ~LiveFactory() = default;
236
240 virtual std::expected<std::shared_ptr<LiveBinding>, ManagedError>
241 create(const std::shared_ptr<SceneAnchor> &anchor) = 0;
242};
243
244} // namespace detail
245
253class Scene {
254public:
259 Scene(Scene &&other) noexcept;
260 Scene &operator=(Scene &&) = delete;
261 Scene(const Scene &) = delete;
262 Scene &operator=(const Scene &) = delete;
267
273 DynamicRef get(std::string_view name, std::source_location origin = std::source_location::current());
274
280 template <class T>
281 requires std::derived_from<T, Widget>
282 Ref<T> get(std::string_view name, std::source_location origin = std::source_location::current());
283
287 Scene &prepare(std::source_location origin = std::source_location::current()) &;
288
292 Scene &&prepare(std::source_location origin = std::source_location::current()) && {
293 static_cast<Scene &>(*this).prepare(origin);
294
295 return std::move(*this);
296 }
297
301 std::expected<void, ManagedError> prepareChecked(std::source_location origin = std::source_location::current());
303 std::expected<void, ManagedError> checked() const;
307 std::expected<std::reference_wrapper<ManagedScene>, ManagedError> managed() const;
313 std::expected<ManagedDiagnosticBatch, TreeError> diagnostics() const;
314
319 Scene &theme(StyleSheet sheet, std::source_location origin = std::source_location::current()) &;
320
325 Scene &&theme(StyleSheet sheet, std::source_location origin = std::source_location::current()) && {
326 applyTheme(sheet, origin);
327
328 return std::move(*this);
329 }
330
337 Scene &styleLayers(StyleLayerOptions options = {}, std::source_location origin = std::source_location::current()) &;
338
344 std::source_location origin = std::source_location::current()) && {
345 static_cast<Scene &>(*this).styleLayers(options, origin);
346
347 return std::move(*this);
348 }
349
351 SceneRef ref() const;
352
357 Scene &style(const StyleStage &stage, std::source_location origin = std::source_location::current()) &;
358
363 Scene &&style(const StyleStage &stage, std::source_location origin = std::source_location::current()) && {
364 static_cast<Scene &>(*this).style(stage, origin);
365
366 return std::move(*this);
367 }
368
375 template <class Source>
376 requires std::constructible_from<StyleStage, Source &&, const StyleOptions &, std::source_location>
377 Scene &style(Source &&source, const StyleOptions &options,
378 std::source_location origin = std::source_location::current()) &;
379
386 template <class Source>
387 requires std::constructible_from<StyleStage, Source &&, const StyleOptions &, std::source_location>
388 Scene &&style(Source &&source, const StyleOptions &options,
389 std::source_location origin = std::source_location::current()) &&;
390
399 Scene &styleLayer(StyleTier tier, std::string name, StyleSheet sheet,
400 std::source_location origin = std::source_location::current()) &;
401
408 Scene &&styleLayer(StyleTier tier, std::string name, StyleSheet sheet,
409 std::source_location origin = std::source_location::current()) && {
410 applyStyleLayer(tier, name, sheet, origin);
411
412 return std::move(*this);
413 }
414
419 Scene &onError(ManagedErrorHandler observer, std::source_location origin = std::source_location::current()) &;
420
425 Scene &&onError(ManagedErrorHandler observer, std::source_location origin = std::source_location::current()) && {
426 detail::SetupFailureScope observerScope({}, nullptr, nullptr);
427 ManagedErrorHandler incomingObserver;
428
429 incomingObserver.swap(observer);
430 static_cast<Scene &>(*this).onError(std::move(incomingObserver), origin);
431
432 return std::move(*this);
433 }
434
440 Scene &reportOnError(SceneReportHandler sink = {}, std::source_location origin = std::source_location::current()) &;
441
446 Scene &&reportOnError(SceneReportHandler sink = {},
447 std::source_location origin = std::source_location::current()) && {
448 detail::SetupFailureScope reportingScope({}, nullptr, nullptr);
449 SceneReportHandler incomingSink;
450
451 incomingSink.swap(sink);
452 static_cast<Scene &>(*this).reportOnError(std::move(incomingSink), origin);
453
454 return std::move(*this);
455 }
456
475 template <detail::SceneConfiguration Callback>
476 Scene &configure(Callback callback, std::source_location origin = std::source_location::current()) & {
477 configureImpl(callback, origin);
478
479 return *this;
480 }
481
488 template <detail::SceneConfiguration Callback>
489 Scene &&configure(Callback callback, std::source_location origin = std::source_location::current()) && {
490 configureImpl(callback, origin);
491
492 return std::move(*this);
493 }
494
507 template <detail::SceneStop Callback>
508 Scene &onStop(Callback callback, std::source_location origin = std::source_location::current()) & {
509 stopImpl(callback, origin);
510
511 return *this;
512 }
513
519 template <detail::SceneStop Callback>
520 Scene &&onStop(Callback callback, std::source_location origin = std::source_location::current()) && {
521 stopImpl(callback, origin);
522
523 return std::move(*this);
524 }
525
529 template <class Info, class Callback>
530 requires std::same_as<std::remove_cvref_t<Info>, ui::KeyInfo> && portals::detail::ManagedAction<Callback, KeyEvent>
531 Scene &onKey(KeySelection selection, Info info, Callback callback,
532 std::source_location origin = std::source_location::current()) & {
533 onAnnotatedImpl(std::move(selection), std::move(info), callback, origin);
534 return *this;
535 }
536
540 template <class Info, class Callback>
541 requires std::same_as<std::remove_cvref_t<Info>, ui::KeyInfo> && portals::detail::ManagedAction<Callback, KeyEvent>
542 Scene &&onKey(KeySelection selection, Info info, Callback callback,
543 std::source_location origin = std::source_location::current()) && {
544 onAnnotatedImpl(std::move(selection), std::move(info), callback, origin);
545 return std::move(*this);
546 }
547
552 template <portals::detail::ShortcutSource Source, class Info, class Callback>
553 requires std::same_as<std::remove_cvref_t<Info>, ui::KeyInfo> && portals::detail::ManagedAction<Callback, KeyEvent>
554 Scene &onKey(Source &&source, Info info, Callback callback,
555 std::source_location origin = std::source_location::current()) & {
557 portals::detail::prepareShortcut(std::forward<Source>(source), {}), {KeyAction::PRESS}, {});
558 return onKey(std::move(selection), std::move(info), std::move(callback), origin);
559 }
560
565 template <portals::detail::ShortcutSource Source, class Info, class Callback>
566 requires std::same_as<std::remove_cvref_t<Info>, ui::KeyInfo> && portals::detail::ManagedAction<Callback, KeyEvent>
567 Scene &&onKey(Source &&source, Info info, Callback callback,
568 std::source_location origin = std::source_location::current()) && {
569 onKey(std::forward<Source>(source), std::move(info), std::move(callback), origin);
570 return std::move(*this);
571 }
572
579 template <class Callback = detail::QuitCommand>
581 Scene &onKey(const KeySelection &selection, Callback callback,
582 std::source_location origin = std::source_location::current()) & {
583 onSelectionImpl(selection, callback, origin);
584
585 return *this;
586 }
587
594 template <class Callback = detail::QuitCommand>
596 Scene &&onKey(const KeySelection &selection, Callback callback,
597 std::source_location origin = std::source_location::current()) && {
598 onSelectionImpl(selection, callback, origin);
599
600 return std::move(*this);
601 }
602
609 template <class Callback = detail::QuitCommand>
611 Scene &onKey(KeyEvent chord, Callback callback, std::source_location origin = std::source_location::current()) & {
612 onKeyImpl(chord, callback, origin);
613
614 return *this;
615 }
616
623 template <class Callback = detail::QuitCommand>
625 Scene &&onKey(KeyEvent chord, Callback callback, std::source_location origin = std::source_location::current()) && {
626 onKeyImpl(chord, callback, origin);
627
628 return std::move(*this);
629 }
630
638 template <portals::detail::ShortcutSource Source, class Callback = detail::QuitCommand>
640 Scene &onKey(Source &&source, Callback callback, std::source_location origin = std::source_location::current()) & {
641 onShortcutSourceImpl(std::forward<decltype(source)>(source), callback, {}, {}, origin);
642
643 return *this;
644 }
645
653 template <portals::detail::ShortcutSource Source, class Callback = detail::QuitCommand>
655 Scene &&onKey(Source &&source, Callback callback, std::source_location origin = std::source_location::current()) && {
656 onShortcutSourceImpl(std::forward<decltype(source)>(source), callback, {}, {}, origin);
657
658 return std::move(*this);
659 }
660
670 template <portals::detail::ShortcutSource Source, class Callback = detail::QuitCommand>
672 Scene &onKey(Source &&source, Callback callback, ShortcutBehavior behavior, ShortcutOptions options = {},
673 std::source_location origin = std::source_location::current()) & {
674 onShortcutSourceImpl(std::forward<decltype(source)>(source), callback, behavior, options, origin);
675
676 return *this;
677 }
678
688 template <portals::detail::ShortcutSource Source, class Callback = detail::QuitCommand>
690 Scene &&onKey(Source &&source, Callback callback, ShortcutBehavior behavior, ShortcutOptions options = {},
691 std::source_location origin = std::source_location::current()) && {
692 onShortcutSourceImpl(std::forward<decltype(source)>(source), callback, behavior, options, origin);
693
694 return std::move(*this);
695 }
696
703 template <class Callback = detail::QuitCommand>
705 Scene &onKey(std::initializer_list<key::Chord> source, Callback callback,
706 std::source_location origin = std::source_location::current()) & {
707 onShortcutSourceImpl(std::forward<decltype(source)>(source), callback, {}, {}, origin);
708
709 return *this;
710 }
711
718 template <class Callback = detail::QuitCommand>
720 Scene &&onKey(std::initializer_list<key::Chord> source, Callback callback,
721 std::source_location origin = std::source_location::current()) && {
722 onShortcutSourceImpl(std::forward<decltype(source)>(source), callback, {}, {}, origin);
723
724 return std::move(*this);
725 }
726
735 template <class Callback = detail::QuitCommand>
737 Scene &onKey(std::initializer_list<key::Chord> source, Callback callback, ShortcutBehavior behavior,
738 ShortcutOptions options = {}, std::source_location origin = std::source_location::current()) & {
739 onShortcutSourceImpl(std::forward<decltype(source)>(source), callback, behavior, options, origin);
740
741 return *this;
742 }
743
752 template <class Callback = detail::QuitCommand>
754 Scene &&onKey(std::initializer_list<key::Chord> source, Callback callback, ShortcutBehavior behavior,
755 ShortcutOptions options = {}, std::source_location origin = std::source_location::current()) && {
756 onShortcutSourceImpl(std::forward<decltype(source)>(source), callback, behavior, options, origin);
757
758 return std::move(*this);
759 }
760
765 std::expected<ApplicationStats, ManagedError> run(std::stop_token stop = {},
766 std::source_location origin = std::source_location::current());
772 std::expected<ApplicationStats, ManagedError> run(ApplicationTerminal &terminal, std::stop_token stop = {},
773 std::source_location origin = std::source_location::current());
774
780 std::expected<void, ManagedError> start(ApplicationReadyTerminal &terminal, std::stop_token stop = {},
781 std::source_location origin = std::source_location::current());
782
787 std::expected<ApplicationStep, ManagedError> step(std::source_location origin = std::source_location::current());
788
795 std::expected<void, ManagedError> quit(std::source_location origin = std::source_location::current());
796
805 int runApp(std::stop_token stop = {}, std::source_location origin = std::source_location::current());
806
812 int runApp(ApplicationTerminal &terminal, std::stop_token stop = {},
813 std::source_location origin = std::source_location::current());
814
823 int runApp(int argc, const char *const *argv, CommandLineParser parser, std::stop_token stop = {},
824 std::source_location origin = std::source_location::current());
825
835 int runApp(ApplicationTerminal &terminal, int argc, const char *const *argv, CommandLineParser parser,
836 std::stop_token stop = {}, std::source_location origin = std::source_location::current());
837
843 Scene &applicationOptions(std::function<ApplicationOptions()> provider,
844 std::source_location origin = std::source_location::current()) &;
845
850 std::expected<void, ManagedError> close(std::source_location origin = std::source_location::current());
851
852private:
853 friend struct detail::SceneAccess;
854 using Configuration = portals::detail::MoveOnlyFunction<std::expected<void, ManagedError>(ManagedScene &)>;
855 using Stop = portals::detail::MoveOnlyFunction<std::expected<void, ManagedError>()>;
856 struct State;
857 detail::SetupFailureScope setupScope(const char *execution) noexcept;
858 static Application &admittedApplication(ManagedScene &scene) noexcept;
859
860 template <detail::SceneConfiguration Callback> void configureImpl(Callback &callback, std::source_location origin) {
861 detail::SetupFailureScope configurationScope({}, nullptr, nullptr);
862
863 if (!admitConfiguration(false, origin)) {
864 return;
865 }
866
867 try {
868 addConfiguration(
869 [callback = std::move(callback)](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
870 const auto invoke = [&]() -> decltype(auto) {
871 if constexpr (std::invocable<Callback &, ManagedScene &>) {
872 return std::invoke(callback, scene);
873 } else {
874 return std::invoke(callback, scene, admittedApplication(scene));
875 }
876 };
877
878 if constexpr (std::same_as<decltype(invoke()), void>) {
879 invoke();
880
881 return {};
882 } else {
883 return invoke();
884 }
885 },
886 false, origin);
887 } catch (const std::bad_alloc &) {
888 configurationException(TreeError::NO_MEMORY, origin);
889 } catch (...) {
890 configurationException(TreeError::CALLBACK_FAILED, origin);
891 }
892 }
893
894 template <detail::SceneStop Callback> void stopImpl(Callback &callback, std::source_location origin) {
895 detail::SetupFailureScope scope({}, nullptr, nullptr);
896 detail::CurrentSceneScope currentMask;
897
898 if (!admitConfiguration(false, origin)) {
899 return;
900 }
901
902 try {
903 setStop(
904 [callback = std::move(callback)]() mutable -> std::expected<void, ManagedError> {
905 if constexpr (std::same_as<std::invoke_result_t<Callback &>, void>) {
906 std::invoke(callback);
907
908 return {};
909 } else {
910 return std::invoke(callback);
911 }
912 },
913 origin);
914 } catch (const std::bad_alloc &) {
915 configurationException(TreeError::NO_MEMORY, origin);
916 } catch (...) {
917 configurationException(TreeError::CALLBACK_FAILED, origin);
918 }
919 }
920
921 template <class Callback>
922 requires portals::detail::ManagedAction<Callback, KeyEvent>
923 void onKeyImpl(KeyEvent chord, Callback &callback, std::source_location origin) {
924 detail::commandOrigin(callback, origin);
925 if (!admitConfiguration(true, origin)) {
926 return;
927 }
928
929 try {
930 addConfiguration(
931 [chord, declaration = detail::retainAction(callback),
932 callback = std::move(callback)](ManagedScene &scene) mutable {
933 (void)declaration;
934 return scene.onKey(chord, std::move(callback));
935 },
936 true, origin);
937 } catch (const std::bad_alloc &) {
938 configurationException(TreeError::NO_MEMORY, origin);
939 } catch (...) {
940 configurationException(TreeError::CALLBACK_FAILED, origin);
941 }
942 }
943
944 template <class Info, class Callback>
945 void onAnnotatedImpl(KeySelection selection, Info info, Callback &callback, std::source_location origin) {
946 detail::commandOrigin(callback, origin);
947 if (!admitConfiguration(true, origin)) {
948 return;
949 }
950 try {
951 addConfiguration(
952 [selection, info = std::move(info), declaration = detail::retainAction(callback),
953 callback = std::move(callback), origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
954 (void)declaration;
955 auto metadata = info.resolve(scene);
956 if (!metadata) {
957 return std::unexpected(metadata.error());
958 }
959 auto result = scene.onKey(selection, std::move(*metadata), std::move(callback), origin);
960 return result ? std::expected<void, ManagedError>{} : std::unexpected(result.error());
961 },
962 true, origin);
963 } catch (const std::bad_alloc &) {
964 configurationException(TreeError::NO_MEMORY, origin);
965 } catch (...) {
966 configurationException(TreeError::CALLBACK_FAILED, origin);
967 }
968 }
969
970 template <class Callback>
971 void onSelectionImpl(const KeySelection &selection, Callback &callback, std::source_location origin) {
972 detail::commandOrigin(callback, origin);
973 if (!admitConfiguration(true, origin)) {
974 return;
975 }
976
977 const auto &shortcut = portals::detail::KeySelectionAccess::shortcut(selection);
978
979 if (!shortcut || !*shortcut) {
980 shortcutConfigurationFailure(shortcut ? ShortcutError{ShortcutErrorKind::INVALID_CHORD, 0} : shortcut.error(),
981 origin);
982
983 return;
984 }
985
986 try {
987 addConfiguration(
988 [selection, declaration = detail::retainAction(callback), callback = std::move(callback),
989 origin](ManagedScene &scene) mutable {
990 (void)declaration;
991 return scene.onKey(selection, std::move(callback), origin);
992 },
993 true, origin);
994 } catch (const std::bad_alloc &) {
995 configurationException(TreeError::NO_MEMORY, origin);
996 } catch (...) {
997 configurationException(TreeError::CALLBACK_FAILED, origin);
998 }
999 }
1000
1001 template <class Source, class Callback>
1002 void onShortcutSourceImpl(Source &&source, Callback &callback, ShortcutBehavior behavior, ShortcutOptions options,
1003 std::source_location origin) {
1004 if (!admitConfiguration(true, origin)) {
1005 return;
1006 }
1007
1008 try {
1009 auto shortcut = portals::detail::prepareShortcut(std::forward<decltype(source)>(source), options);
1010
1011 onShortcutImpl(shortcut, callback, behavior, options, origin);
1012 } catch (const std::bad_alloc &) {
1013 configurationException(TreeError::NO_MEMORY, origin);
1014 } catch (...) {
1015 configurationException(TreeError::CALLBACK_FAILED, origin);
1016 }
1017 }
1018
1019 template <class Callback>
1020 void onShortcutImpl(std::expected<Shortcut, ShortcutError> &shortcut, Callback &callback, ShortcutBehavior behavior,
1021 ShortcutOptions options, std::source_location origin) {
1022 detail::commandOrigin(callback, origin);
1023 if (!admitConfiguration(true, origin)) {
1024 return;
1025 }
1026
1027 if (!shortcut) {
1028 shortcutConfigurationFailure(shortcut.error(), origin);
1029
1030 return;
1031 }
1032
1033 try {
1034 addConfiguration(
1035 [shortcut = std::move(*shortcut), declaration = detail::retainAction(callback), callback = std::move(callback),
1036 behavior, options, origin](ManagedScene &scene) mutable {
1037 (void)declaration;
1038 return scene.onKey(std::move(shortcut), std::move(callback), behavior, options, origin);
1039 },
1040 true, origin);
1041 } catch (const std::bad_alloc &) {
1042 configurationException(TreeError::NO_MEMORY, origin);
1043 } catch (...) {
1044 configurationException(TreeError::CALLBACK_FAILED, origin);
1045 }
1046 }
1047
1048 template <detail::SceneConfiguration Callback> void onEventImpl(Callback &callback, std::source_location origin) {
1049 if (!admitConfiguration(true, origin)) {
1050 return;
1051 }
1052
1053 try {
1054 addConfiguration(std::move(callback), true, origin);
1055 } catch (const std::bad_alloc &) {
1056 configurationException(TreeError::NO_MEMORY, origin);
1057 } catch (...) {
1058 configurationException(TreeError::CALLBACK_FAILED, origin);
1059 }
1060 }
1061
1062 void applyLiveBinding(std::shared_ptr<detail::LiveFactory> factory, std::source_location origin);
1063 void setupFailure(ManagedError failure, std::source_location origin);
1064 void applyTheme(const StyleSheet &sheet, std::source_location origin);
1065 void applyStyleLayer(StyleTier tier, const std::string &name, const StyleSheet &sheet, std::source_location origin);
1066 Scene(Configuration recipe, SceneOptions options, std::source_location origin);
1067 bool admitConfiguration(bool runtime, std::source_location origin);
1068 void addConfiguration(Configuration callback, bool runtime, std::source_location origin);
1069 void setStop(Stop callback, std::source_location origin);
1070 void configurationException(TreeError cause, std::source_location origin);
1071 void shortcutConfigurationFailure(ShortcutError cause, std::source_location origin);
1072 std::expected<ApplicationStats, ManagedError> runImpl(ApplicationTerminal *terminal, std::stop_token stop,
1073 std::source_location origin);
1074 int runAppImpl(ApplicationTerminal *terminal, std::stop_token stop, std::source_location origin,
1075 std::size_t droppedErrors = 0);
1076 std::expected<void, ManagedError> factoryResultChecked() const;
1077 std::size_t applyFactoryCleanup(const detail::FactoryCleanup &cleanup, std::source_location origin);
1078 bool deliverFactoryReport(const SceneReport &report, std::shared_ptr<SceneReportHandler> sink);
1079 int runAppReported(const RunAppOptions &options, std::shared_ptr<SceneReportHandler> sink,
1080 std::source_location origin, std::size_t droppedErrors);
1081 int runAppPreflight(ApplicationTerminal *terminal, int argc, const char *const *argv, CommandLineParser &parser,
1082 std::stop_token stop, std::source_location origin);
1083
1084 std::thread::id owner_;
1085 std::unique_ptr<State> state_;
1086};
1087
1088namespace detail {
1092 static std::weak_ptr<SceneAnchor> callbackContext(ManagedScene &owner) noexcept {
1093 return owner.facadeContext();
1094 }
1095
1099 static std::expected<void, ManagedError> requireBackground(ManagedScene &owner) {
1100 auto allowed = owner.boundary(ManagedPhase::BIND, owner.root_);
1101
1102 if (allowed) {
1103 owner.asyncEnabled_ = true;
1104 }
1105
1106 return allowed;
1107 }
1108
1113 static std::expected<void, ManagedError> admitActivity(ManagedScene &owner, std::shared_ptr<SceneActivity> activity) {
1114 return owner.admitActivity(std::move(activity));
1115 }
1116
1121 static std::expected<void, ManagedError> factoryResultChecked(const Scene &owner) {
1122 return owner.factoryResultChecked();
1123 }
1124
1130 static std::size_t applyFactoryCleanup(Scene &owner, const FactoryCleanup &cleanup, std::source_location origin) {
1131 return owner.applyFactoryCleanup(cleanup, origin);
1132 }
1133
1139 static bool deliverFactoryReport(Scene &owner, const SceneReport &report, std::shared_ptr<SceneReportHandler> sink) {
1140 return owner.deliverFactoryReport(report, std::move(sink));
1141 }
1142
1150 static int runApp(Scene &owner, const RunAppOptions &options, std::shared_ptr<SceneReportHandler> sink,
1151 std::source_location origin, std::size_t droppedErrors) {
1152 return owner.runAppReported(options, std::move(sink), origin, droppedErrors);
1153 }
1154
1160 static std::expected<void, ManagedError>
1161 attachThemeSelector(ManagedScene &owner, const std::optional<ManagedError> *setupFailure = nullptr) {
1162 return owner.attachThemeSelector(setupFailure);
1163 }
1164
1168 static Application &application(ManagedScene &owner) noexcept {
1169 return owner.app_;
1170 }
1171
1177 static std::expected<StyleRoleRegistration, ManagedError>
1178 registerPreparedRoles(ManagedScene &owner, Node<Widget> node, std::initializer_list<std::string_view> names) {
1179 const auto failure = [&](TreeError cause) {
1180 return std::unexpected(ManagedError{ManagedPhase::STYLE, node.id(), cause, {}, {}});
1181 };
1182 if (owner.owner_ != std::this_thread::get_id()) {
1183 return failure(TreeError::WRONG_THREAD);
1184 }
1185 if (owner.closed_) {
1186 return failure(TreeError::CLOSED);
1187 }
1188 if (!owner.preparing_ || !owner.servicingActivities_ || owner.reporting_ || owner.styling_ || owner.stylesDirty_) {
1189 return failure(TreeError::WOULD_BLOCK);
1190 }
1191 if (!owner.find(node)) {
1192 return failure(TreeError::INVALID_ARGUMENT);
1193 }
1194 auto registered = owner.styles_.registerRoles(node, names);
1195 if (!registered) {
1196 return std::unexpected(ManagedError{ManagedPhase::STYLE, node.id(), registered.error(), {}, {}});
1197 }
1198 return *registered;
1199 }
1200
1205 static std::expected<StyleRoleRegistration, ManagedError>
1207 std::initializer_list<std::string_view> names) {
1208 if (owner.owner_ != std::this_thread::get_id()) {
1209 return std::unexpected(ManagedError{ManagedPhase::STYLE, node.id(), TreeError::WRONG_THREAD, {}, {}});
1210 }
1211 if (owner.closed_ || owner.reporting_ || owner.styling_ || owner.stylesDirty_) {
1212 return std::unexpected(ManagedError{
1213 ManagedPhase::STYLE, node.id(), owner.closed_ ? TreeError::CLOSED : TreeError::WOULD_BLOCK, {}, {}});
1214 }
1215 auto replaced = owner.styles_.replaceRoles(registration, names);
1216 if (!replaced) {
1217 return std::unexpected(ManagedError{ManagedPhase::STYLE, node.id(), replaced.error(), {}, {}});
1218 }
1219 return std::move(*replaced);
1220 }
1221
1226 static void beforeClose(ManagedScene &owner, void *context,
1227 std::expected<void, ManagedError> (*callback)(void *)) noexcept {
1228 owner.closeContext_ = context;
1229 owner.beforeClose_ = callback;
1230 }
1231
1235 static void retainCloseFailure(ManagedScene &owner) {
1236 owner.retainCloseFailure();
1237 }
1238
1242 static void currentOwner(ManagedScene &owner, std::weak_ptr<SceneAnchor> anchor) noexcept {
1243 owner.facade_ = std::move(anchor);
1244 }
1245
1247 static SceneRef currentRef() noexcept {
1248 return SceneRef(CurrentSceneScope::snapshot(), std::this_thread::get_id());
1249 }
1250
1254 static CurrentSceneScope currentScope(Scene &owner) noexcept {
1255 return CurrentSceneScope(owner.ref().anchor_);
1256 }
1257
1261 static SetupFailureScope setupScope(Scene &owner) noexcept {
1262 return owner.setupScope("scene.setup");
1263 }
1264
1269 static bool shortReported(const ManagedScene &owner, const ManagedError &failure) noexcept {
1270 return owner.shortReported(failure);
1271 }
1272
1278 template <SceneConfiguration Callback>
1279 static void onClick(Scene &owner, Callback &callback, std::source_location origin) {
1280 owner.onEventImpl(callback, origin);
1281 }
1282
1288 template <SceneConfiguration Callback>
1289 static void onEditing(Scene &owner, Callback &callback, std::source_location origin) {
1290 owner.onEventImpl(callback, origin);
1291 }
1292
1298 template <SceneConfiguration Callback>
1299 static void onLayout(Scene &owner, Callback &callback, std::source_location origin) {
1300 owner.onEventImpl(callback, origin);
1301 }
1302
1307 static void live(Scene &owner, std::shared_ptr<LiveFactory> factory, std::source_location origin) {
1308 owner.applyLiveBinding(std::move(factory), origin);
1309 }
1310
1315 static void setupFailure(Scene &owner, ManagedError failure, std::source_location origin) {
1316 owner.setupFailure(std::move(failure), origin);
1317 }
1318
1323 static void theme(Scene &owner, const StyleSheet &sheet, std::source_location origin) {
1324 owner.applyTheme(sheet, origin);
1325 }
1326
1333 static void styleLayer(Scene &owner, StyleTier tier, const std::string &name, const StyleSheet &sheet,
1334 std::source_location origin) {
1335 owner.applyStyleLayer(tier, name, sheet, origin);
1336 }
1337
1343 template <detail::SceneConfiguration Callback>
1344 static void configure(Scene &owner, Callback &callback, std::source_location origin) {
1345 owner.configureImpl(callback, origin);
1346 }
1347
1354 template <class Callback>
1356 static void onKey(Scene &owner, KeyEvent chord, Callback &callback, std::source_location origin) {
1357 owner.onKeyImpl(chord, callback, origin);
1358 }
1359
1366 template <class Callback>
1368 static void onSelection(Scene &owner, const KeySelection &selection, Callback &callback,
1369 std::source_location origin) {
1370 owner.onSelectionImpl(selection, callback, origin);
1371 }
1372
1381 template <class Callback>
1383 static void onShortcut(Scene &owner, std::expected<Shortcut, ShortcutError> &shortcut, Callback &callback,
1384 ShortcutBehavior behavior, ShortcutOptions options, std::source_location origin) {
1385 owner.onShortcutImpl(shortcut, callback, behavior, options, origin);
1386 }
1387
1396 template <class Callback>
1398 static void onShortcut(Scene &owner, std::expected<std::shared_ptr<Shortcut>, ShortcutError> &shortcut,
1399 Callback &callback, ShortcutBehavior behavior, ShortcutOptions options,
1400 std::source_location origin) {
1401 if (!shortcut) {
1402 std::expected<Shortcut, ShortcutError> failure = std::unexpected(shortcut.error());
1403
1404 owner.onShortcutImpl(failure, callback, behavior, options, origin);
1405
1406 return;
1407 }
1408
1409 owner.onShortcutSourceImpl(std::move(**shortcut), callback, behavior, options, origin);
1410 }
1411
1415 static bool notifyingRunFailure(const ManagedScene &owner) noexcept {
1416 return owner.notifyingRunFailure_;
1417 }
1418
1421 static bool primaryRecorded(const ManagedScene &owner) noexcept {
1422 return owner.dialogPrimaryRecorded_;
1423 }
1424
1429 static bool runFailureNotified(const ManagedScene &owner) noexcept {
1430 return owner.runFailureNotified_;
1431 }
1432
1436 static std::pair<std::size_t, std::size_t> reportCounts(const ManagedScene &owner) noexcept {
1437 return {owner.errorCount_, owner.droppedErrors_};
1438 }
1439
1445 static Scene create(portals::detail::MoveOnlyFunction<std::expected<void, ManagedError>(ManagedScene &)> recipe,
1446 SceneOptions options, std::source_location origin) {
1447 return Scene(std::move(recipe), options, origin);
1448 }
1449};
1450} // namespace detail
1451
1458inline int runApp(Scene &owner, std::stop_token stop = {},
1459 std::source_location origin = std::source_location::current()) {
1460 return owner.runApp(stop, origin);
1461}
1462
1469inline int runApp(Scene &owner, ApplicationTerminal &terminal, std::stop_token stop = {},
1470 std::source_location origin = std::source_location::current()) {
1471 return owner.runApp(terminal, stop, origin);
1472}
1473
1474// The public contract is documented on Scene::get in ui_scene.hpp.
1475template <class T>
1476 requires std::derived_from<T, Widget>
1477Ref<T> Scene::get(std::string_view name, std::source_location origin) {
1478 return detail::NamedAccess::request<T>({ref().anchor_, owner_, std::string(name), origin});
1479}
1480
1481} // namespace portals::ui
Exclusive ready-only transport borrowed by an application session. Every operation must return withou...
Definition application.hpp:162
Custom/replay terminal borrowed for exactly one run; no competing I/O is allowed. The owner retains i...
Definition application.hpp:112
One UI owner for scheduler, tree, routing and a single terminal run. All calls/destruction except req...
Definition application.hpp:358
Copyable immutable owning shortcut selection, or a deferred typed construction error....
Definition shortcut.hpp:171
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
NodeId id() const noexcept
Copy the stable diagnostic identity.
Definition widget.hpp:109
std::expected< StyleRoleRegistration, StyleError > registerRoles(Node< Widget > node, std::span< const std::string_view > names)
Register an existing bound node for a bounded semantic projection.
std::expected< StyleRoleRegistration, StyleError > replaceRoles(const StyleRoleRegistration &registration, std::span< const std::string_view > names)
Atomically replace the bounded names of a live semantic registration.
UI-thread scoped registration; the engine retains only a weak observer. Copies share participation....
Definition style.hpp:151
Cheap owning immutable snapshot of named definitions and defaults. Const snapshot reads are concurren...
Definition ui_control_context.hpp:632
Dynamic named observation with checked caption/editor and Button capabilities. Copies own the request...
Definition ui_ref.hpp:2649
Consuming metadata for one canonical annotated registration; refs resolve after complete mount.
Definition ui_key_info.hpp:10
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
Weak facade observation, stable across Scene moves and revoked before capture cleanup....
Definition ui_scene.hpp:90
SceneRef()=default
Construct an empty observer; operations return CLOSED.
std::expected< void, ManagedError > quit(std::source_location origin=std::source_location::current()) const
Single-use lazy owner of one Application and ManagedScene; no second runtime. Construct and operate o...
Definition ui_scene.hpp:253
Scene && onKey(Source &&source, Callback callback, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:655
std::expected< void, ManagedError > prepareChecked(std::source_location origin=std::source_location::current())
~Scene()
Cancel and finish an active session, then close its managed owner before releasing Application....
Scene & onKey(Source &&source, Callback callback, ShortcutBehavior behavior, ShortcutOptions options={}, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:672
Scene & theme(StyleSheet sheet, std::source_location origin=std::source_location::current()) &
DynamicRef get(std::string_view name, std::source_location origin=std::source_location::current())
Scene && onKey(KeySelection selection, Info info, Callback callback, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:542
Scene & onStop(Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:508
std::expected< void, ManagedError > start(ApplicationReadyTerminal &terminal, std::stop_token stop={}, std::source_location origin=std::source_location::current())
Scene & onError(ManagedErrorHandler observer, std::source_location origin=std::source_location::current()) &
Scene && reportOnError(SceneReportHandler sink={}, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:446
Scene && onKey(KeyEvent chord, Callback callback, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:625
std::expected< std::reference_wrapper< ManagedScene >, ManagedError > managed() const
Scene && theme(StyleSheet sheet, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:325
int runApp(ApplicationTerminal &terminal, int argc, const char *const *argv, CommandLineParser parser, std::stop_token stop={}, std::source_location origin=std::source_location::current())
Same preflight boundary with a borrowed custom terminal.
Scene & onKey(std::initializer_list< key::Chord > source, Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:705
Scene && prepare(std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:292
std::expected< ApplicationStats, ManagedError > run(std::stop_token stop={}, std::source_location origin=std::source_location::current())
std::expected< ApplicationStats, ManagedError > run(ApplicationTerminal &terminal, std::stop_token stop={}, std::source_location origin=std::source_location::current())
Scene && onKey(const KeySelection &selection, Callback callback, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:596
std::expected< void, ManagedError > close(std::source_location origin=std::source_location::current())
Scene && onKey(std::initializer_list< key::Chord > source, Callback callback, ShortcutBehavior behavior, ShortcutOptions options={}, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:754
Scene & onKey(KeySelection selection, Info info, Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:531
Scene & style(const StyleStage &stage, std::source_location origin=std::source_location::current()) &
Scene & onKey(const KeySelection &selection, Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:581
Scene && onStop(Callback callback, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:520
Scene & onKey(Source &&source, Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:640
Scene(Scene &&other) noexcept
Transfer a UI-affine owner between operations, including between session steps. Wrong-thread moves an...
Scene && styleLayer(StyleTier tier, std::string name, StyleSheet sheet, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:408
int runApp(std::stop_token stop={}, std::source_location origin=std::source_location::current())
Run a standalone scene with standard post-restoration error reporting.
Scene & reportOnError(SceneReportHandler sink={}, std::source_location origin=std::source_location::current()) &
std::expected< void, ManagedError > quit(std::source_location origin=std::source_location::current())
Request orderly exit through the existing application cancellation path.
Scene && onError(ManagedErrorHandler observer, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:425
Scene & configure(Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:476
Scene && onKey(std::initializer_list< key::Chord > source, Callback callback, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:720
std::expected< void, ManagedError > checked() const
std::expected< ManagedDiagnosticBatch, TreeError > diagnostics() const
std::expected< ApplicationStep, ManagedError > step(std::source_location origin=std::source_location::current())
int runApp(ApplicationTerminal &terminal, std::stop_token stop={}, std::source_location origin=std::source_location::current())
Scene && onKey(Source &&source, Info info, Callback callback, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:567
Scene & onKey(Source &&source, Info info, Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:554
Scene & styleLayer(StyleTier tier, std::string name, StyleSheet sheet, std::source_location origin=std::source_location::current()) &
Add one scene-owned override; enable styleLayers() before this configuration.
SceneRef ref() const
Scene && style(const StyleStage &stage, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:363
Scene & onKey(KeyEvent chord, Callback callback, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:611
Scene & onKey(std::initializer_list< key::Chord > source, Callback callback, ShortcutBehavior behavior, ShortcutOptions options={}, std::source_location origin=std::source_location::current()) &
Definition ui_scene.hpp:737
Scene && styleLayers(StyleLayerOptions options={}, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:343
Scene & styleLayers(StyleLayerOptions options={}, std::source_location origin=std::source_location::current()) &
Opt into independent theme/application/user ownership at the existing configuration boundary.
Scene && configure(Callback callback, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:489
Scene && onKey(Source &&source, Callback callback, ShortcutBehavior behavior, ShortcutOptions options={}, std::source_location origin=std::source_location::current()) &&
Definition ui_scene.hpp:690
Scene & prepare(std::source_location origin=std::source_location::current()) &
int runApp(int argc, const char *const *argv, CommandLineParser parser, std::stop_token stop={}, std::source_location origin=std::source_location::current())
Parse copied process arguments once before preparing the application or mounting widgets.
Scene & applicationOptions(std::function< ApplicationOptions()> provider, std::source_location origin=std::source_location::current()) &
Store a lazy application policy provider, invoked after CLI preflight and before Application::create.
Copyable immutable owning style payload with one shared stage identity. Independent unnamed stages co...
Definition ui_style.hpp:39
Allocation-free UI execution publication; an empty scope suspends the caller's scene.
Definition current_scene.hpp:37
static std::weak_ptr< SceneAnchor > snapshot() noexcept
Definition current_scene.hpp:56
static void retain(const ManagedError &failure) noexcept
FactoryCleanupScope(FactoryCleanup *collector=nullptr) noexcept
Allocation-free current-thread setup context; nested independent scopes restore their parent.
Definition setup_failure.hpp:57
A compact action optionally receives owning event parameters.
Definition managed.hpp:239
Admit exact configuration results without silently discarding a checked failure.
Definition ui_scene.hpp:55
Exact owning shutdown results, without admitting silently discarded errors.
Definition ui_scene.hpp:70
@ PRESS
Key press; the only action emitted by the VT decoder.
Definition input.hpp:207
@ STYLE
Register or apply styles, including a theme change.
Definition managed_diagnostics.hpp:52
@ BIND
Register a managed callback, binding or presentation adapter.
Definition managed_diagnostics.hpp:51
std::function< void(const ManagedDiagnostic &)> ManagedErrorHandler
Scene-owned UI observer; the diagnostic is borrowed only until the call returns.
Definition managed_diagnostics.hpp:154
StyleTier
Independent cascade priority, before selector specificity.
Definition style.hpp:251
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
@ WRONG_THREAD
Operation requires the tree's UI thread.
Definition widget_types.hpp:28
@ 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
Finite runner and component policies; one owner services all I/O.
Definition application.hpp:76
Owning key value without an inferred physical keyboard scan code.
Definition input.hpp:213
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
Finite managed bookkeeping budgets, independent of the existing tree/queue limits.
Definition managed.hpp:334
Borrowed clock service, invoked under the scheduler mutex on UI or producer threads....
Definition scheduler.hpp:57
Command admission independent of low-level KeyEvent binding behavior.
Definition shortcut.hpp:51
Allocation-free diagnostic independent of source and scene lifetime.
Definition shortcut.hpp:34
Configurable finite parser limits; every value must be positive.
Definition shortcut.hpp:44
Aggregate logical owning payload budgets; base slots count as layers.
Definition style.hpp:259
Owned immutable-at-use rules; constructing typed values may allocate and throw.
Definition style.hpp:233
static const auto & shortcut(const KeySelection &selection) noexcept
Definition shortcut.hpp:225
static KeySelection make(std::expected< Shortcut, ShortcutError > &&shortcut, std::initializer_list< KeyAction > actions, ShortcutOptions options)
Owning weak stop action for existing compact key/button registrations.
Definition ui_scene.hpp:116
SceneRef scene
Weak stable facade observation.
Definition ui_scene.hpp:117
void operator()() const
Request stop; report exact errors only to a live UI collector.
Definition ui_scene.hpp:121
std::source_location origin
Original action site for recoverable diagnostics.
Definition ui_scene.hpp:118
Checked factory/setup/run policies.
Definition ui_scene.hpp:145
std::stop_token stop
Existing optional cancellation.
Definition ui_scene.hpp:149
ApplicationTerminal * terminal
Borrowed through synchronous run; null selects native.
Definition ui_scene.hpp:148
SceneReportHandler report
Pre-factory sink; nonempty overrides a returned Scene sink, empty preserves it.
Definition ui_scene.hpp:147
SceneOptions scene
Policies for Description factories; an owning Scene retains its policies.
Definition ui_scene.hpp:146
Policies for one lazy facade over the existing managed runtime.
Definition ui_scene.hpp:17
SchedulerClock clock
Optional borrowed replay clock; must outlive run.
Definition ui_scene.hpp:20
ApplicationOptions application
Existing runner policies, applied once at prepare.
Definition ui_scene.hpp:18
std::size_t maxConfigurations
Positive per-queue maximum for deferred configuration callbacks and named lookups.
Definition ui_scene.hpp:21
ControlContext controls
Immutable named-control/defaults snapshot; applied only to this scene's mount.
Definition ui_scene.hpp:23
ManagedOptions managed
Existing managed ownership and diagnostic budgets.
Definition ui_scene.hpp:19
Final owning error envelope or bounded successful-run summary; no live widget references.
Definition ui_scene.hpp:27
std::size_t retainedErrors
Successful-run retained recoverable count; details remain in diagnostics().
Definition ui_scene.hpp:30
std::optional< ManagedError > failure
Exact primary plus independent runner/restoration/cleanup errors.
Definition ui_scene.hpp:28
std::optional< CommandLineError > commandLineFailure
Owning preflight failure, before any terminal open.
Definition ui_scene.hpp:32
std::source_location origin
Primary failure call site, or final run call site for a summary.
Definition ui_scene.hpp:29
std::size_t droppedErrors
Diagnostic overflow, including additional abandoned factory cleanup failures.
Definition ui_scene.hpp:31
Style source admission and existing layer policy.
Definition ui_style.hpp:12
Allocation-free diagnostics from local scenes abandoned during one factory invocation.
Definition ui_scene.hpp:154
std::optional< ManagedError > failure
First exact destructor cleanup failure, in destruction order.
Definition ui_scene.hpp:155
std::size_t attach(ManagedError &primary) const noexcept
std::size_t droppedErrors
Saturating count of later abandoned cleanup failures.
Definition ui_scene.hpp:156
Erased facade-owned binding; concrete bindings reuse the existing LiveTheme controller.
Definition ui_scene.hpp:220
virtual std::expected< bool, ManagedError > attach(ManagedScene &scene, const std::shared_ptr< SceneAnchor > &anchor)=0
Erased owning live descriptor factory invoked only within facade admission. Concrete descriptor ident...
Definition ui_scene.hpp:234
virtual std::expected< std::shared_ptr< LiveBinding >, ManagedError > create(const std::shared_ptr< SceneAnchor > &anchor)=0
static Ref< T > request(const LookupSource &request)
Definition ui_ref.hpp:2618
Internal bridge from consuming recipes to one stable facade owner.
Definition ui_scene.hpp:1090
static bool shortReported(const ManagedScene &owner, const ManagedError &failure) noexcept
Definition ui_scene.hpp:1269
static void onLayout(Scene &owner, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1299
static bool primaryRecorded(const ManagedScene &owner) noexcept
Definition ui_scene.hpp:1421
static void configure(Scene &owner, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1344
static std::expected< StyleRoleRegistration, ManagedError > replaceDocumentRoles(ManagedScene &owner, Node< Widget > node, const StyleRoleRegistration &registration, std::initializer_list< std::string_view > names)
Definition ui_scene.hpp:1206
static Application & application(ManagedScene &owner) noexcept
Definition ui_scene.hpp:1168
static void beforeClose(ManagedScene &owner, void *context, std::expected< void, ManagedError >(*callback)(void *)) noexcept
Definition ui_scene.hpp:1226
static std::weak_ptr< SceneAnchor > callbackContext(ManagedScene &owner) noexcept
Definition ui_scene.hpp:1092
static std::expected< void, ManagedError > factoryResultChecked(const Scene &owner)
Definition ui_scene.hpp:1121
static void onEditing(Scene &owner, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1289
static void live(Scene &owner, std::shared_ptr< LiveFactory > factory, std::source_location origin)
Definition ui_scene.hpp:1307
static bool deliverFactoryReport(Scene &owner, const SceneReport &report, std::shared_ptr< SceneReportHandler > sink)
Definition ui_scene.hpp:1139
static Scene create(portals::detail::MoveOnlyFunction< std::expected< void, ManagedError >(ManagedScene &)> recipe, SceneOptions options, std::source_location origin)
Definition ui_scene.hpp:1445
static std::pair< std::size_t, std::size_t > reportCounts(const ManagedScene &owner) noexcept
Definition ui_scene.hpp:1436
static void onKey(Scene &owner, KeyEvent chord, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1356
static std::expected< void, ManagedError > admitActivity(ManagedScene &owner, std::shared_ptr< SceneActivity > activity)
Definition ui_scene.hpp:1113
static void styleLayer(Scene &owner, StyleTier tier, const std::string &name, const StyleSheet &sheet, std::source_location origin)
Definition ui_scene.hpp:1333
static bool notifyingRunFailure(const ManagedScene &owner) noexcept
Definition ui_scene.hpp:1415
static void currentOwner(ManagedScene &owner, std::weak_ptr< SceneAnchor > anchor) noexcept
Definition ui_scene.hpp:1242
static void onShortcut(Scene &owner, std::expected< Shortcut, ShortcutError > &shortcut, Callback &callback, ShortcutBehavior behavior, ShortcutOptions options, std::source_location origin)
Definition ui_scene.hpp:1383
static void onSelection(Scene &owner, const KeySelection &selection, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1368
static void theme(Scene &owner, const StyleSheet &sheet, std::source_location origin)
Definition ui_scene.hpp:1323
static std::expected< void, ManagedError > requireBackground(ManagedScene &owner)
Definition ui_scene.hpp:1099
static void retainCloseFailure(ManagedScene &owner)
Definition ui_scene.hpp:1235
static void onClick(Scene &owner, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1279
static SetupFailureScope setupScope(Scene &owner) noexcept
Definition ui_scene.hpp:1261
static void onShortcut(Scene &owner, std::expected< std::shared_ptr< Shortcut >, ShortcutError > &shortcut, Callback &callback, ShortcutBehavior behavior, ShortcutOptions options, std::source_location origin)
Definition ui_scene.hpp:1398
static bool runFailureNotified(const ManagedScene &owner) noexcept
Definition ui_scene.hpp:1429
static int runApp(Scene &owner, const RunAppOptions &options, std::shared_ptr< SceneReportHandler > sink, std::source_location origin, std::size_t droppedErrors)
Definition ui_scene.hpp:1150
static void setupFailure(Scene &owner, ManagedError failure, std::source_location origin)
Definition ui_scene.hpp:1315
static SceneRef currentRef() noexcept
Definition ui_scene.hpp:1247
static std::size_t applyFactoryCleanup(Scene &owner, const FactoryCleanup &cleanup, std::source_location origin)
Definition ui_scene.hpp:1130
static CurrentSceneScope currentScope(Scene &owner) noexcept
Definition ui_scene.hpp:1254
static std::expected< StyleRoleRegistration, ManagedError > registerPreparedRoles(ManagedScene &owner, Node< Widget > node, std::initializer_list< std::string_view > names)
Register SDK-owned parts only after style metadata has been flushed.
Definition ui_scene.hpp:1178
static std::expected< void, ManagedError > attachThemeSelector(ManagedScene &owner, const std::optional< ManagedError > *setupFailure=nullptr)
Definition ui_scene.hpp:1161
Stable weak facade publication; mutable fields are accessed only after UI admission.
Definition ui_scene.hpp:209
const std::thread::id owner
Immutable UI identity.
Definition ui_scene.hpp:210
void * state
Borrowed stable facade State, valid only while the anchor is published.
Definition ui_scene.hpp:211
std::shared_ptr< RefTarget > events
Existing weak collector context.
Definition ui_scene.hpp:216