Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
ui_scene_pipeline.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/ui_scene_recipes.hpp>
6
7namespace portals::ui {
8
13inline KeyEvent key(InputKey value, InputModifiers modifiers = {}) {
14 return {value, {}, modifiers, KeyAction::PRESS};
15}
16
21inline KeyEvent character(char32_t scalar, InputModifiers modifiers = {}) {
22 return {InputKey::CHARACTER, scalar, modifiers, KeyAction::PRESS};
23}
24
25namespace detail {
29template <class Action> struct SceneStage {
31
36 friend Scene &operator|(Scene &owner, SceneStage &stage) {
37 stage.action(owner);
38
39 return owner;
40 }
41
46 friend Scene &operator|(Scene &owner, SceneStage &&stage) {
47 stage.action(owner);
48
49 return owner;
50 }
51
56 friend Scene operator|(Scene &&input, SceneStage &stage) {
57 Scene owner(std::move(input));
58
59 stage.action(owner);
60
61 return owner;
62 }
63
68 friend Scene operator|(Scene &&input, SceneStage &&stage) {
69 Scene owner(std::move(input));
70
71 stage.action(owner);
72
73 return owner;
74 }
75};
76
78struct RunStage {
80 std::stop_token stop;
81 std::source_location origin;
82
87 friend std::expected<ApplicationStats, ManagedError> operator|(Scene owner, RunStage stage) {
88 return stage.terminal ? owner.run(*stage.terminal, stage.stop, stage.origin) : owner.run(stage.stop, stage.origin);
89 }
90};
91
95 std::stop_token stop;
96 std::source_location origin;
98
103 friend int operator|(Scene &owner, RunAppStage stage) {
104 if (stage.options.report) {
105 owner.reportOnError(std::move(stage.options.report), stage.origin);
106 }
107
108 return stage.terminal ? owner.runApp(*stage.terminal, stage.stop, stage.origin)
109 : owner.runApp(stage.stop, stage.origin);
110 }
111
116 friend int operator|(Scene &&owner, RunAppStage stage) {
117 return owner | stage;
118 }
119};
120
123 int argc{};
124 const char *const *argv{};
125 CommandLineParser parser;
127 std::stop_token stop;
128 std::source_location origin;
130
135 friend int operator|(Scene &owner, CommandLineRunStage stage) {
136 if (stage.options.report) {
137 owner.reportOnError(std::move(stage.options.report), stage.origin);
138 }
139
140 return stage.terminal
141 ? owner.runApp(*stage.terminal, stage.argc, stage.argv, std::move(stage.parser), stage.stop, stage.origin)
142 : owner.runApp(stage.argc, stage.argv, std::move(stage.parser), stage.stop, stage.origin);
143 }
144
149 friend int operator|(Scene &&owner, CommandLineRunStage stage) {
150 return owner | std::move(stage);
151 }
152};
153
154} // namespace detail
155
159inline auto prepare(std::source_location origin = std::source_location::current()) {
160 return detail::SceneStage{[origin](Scene &owner) {
161 owner.prepare(origin);
162 }};
163}
164
169inline auto theme(StyleSheet sheet, std::source_location origin = std::source_location::current()) {
170 return detail::SceneStage{[sheet = std::move(sheet), origin](Scene &owner) mutable {
171 detail::SceneAccess::theme(owner, sheet, origin);
172 }};
173}
174
179inline auto styleLayers(StyleLayerOptions options = {}, std::source_location origin = std::source_location::current()) {
180 return detail::SceneStage{[options, origin](Scene &owner) {
181 owner.styleLayers(options, origin);
182 }};
183}
184
192inline auto styleLayer(StyleTier tier, std::string name, StyleSheet sheet,
193 std::source_location origin = std::source_location::current()) {
194 return detail::SceneStage{[tier, name = std::move(name), sheet = std::move(sheet), origin](Scene &owner) {
195 detail::SceneAccess::styleLayer(owner, tier, name, sheet, origin);
196 }};
197}
198
203inline auto onError(ManagedErrorHandler observer, std::source_location origin = std::source_location::current()) {
204 return detail::SceneStage{[observer = std::move(observer), origin](Scene &owner) mutable {
205 owner.onError(std::move(observer), origin);
206 }};
207}
208
213inline auto reportOnError(SceneReportHandler sink = {}, std::source_location origin = std::source_location::current()) {
214 return detail::SceneStage{[sink = std::move(sink), origin](Scene &owner) mutable {
215 owner.reportOnError(std::move(sink), origin);
216 }};
217}
218
224template <detail::SceneConfiguration Callback>
225auto configure(Callback callback, std::source_location origin = std::source_location::current()) {
226 return detail::SceneStage{[callback = std::move(callback), origin](Scene &owner) mutable {
227 detail::SceneAccess::configure(owner, callback, origin);
228 }};
229}
230
237template <class Callback = detail::QuitCommand>
238 requires portals::detail::ManagedAction<Callback, KeyEvent>
239auto onKey(KeyEvent chord, Callback callback, std::source_location origin = std::source_location::current()) {
240 return detail::SceneStage{[chord, declaration = detail::retainAction(callback), callback = std::move(callback), origin](Scene &owner) mutable {
241 (void)declaration;
242 detail::SceneAccess::onKey(owner, chord, callback, origin);
243 }};
244}
245
256template <portals::detail::ShortcutSource Source>
257KeySelection keyActions(Source &&source, std::initializer_list<KeyAction> actions, ShortcutOptions options = {}) {
259 portals::detail::prepareShortcut(std::forward<Source>(source), options), actions, options);
260}
261
269inline KeySelection keyActions(std::initializer_list<key::Chord> source, std::initializer_list<KeyAction> actions,
270 ShortcutOptions options = {}) {
271 return portals::detail::KeySelectionAccess::make(portals::detail::prepareShortcut(source, options), actions, options);
272}
273
281template <portals::detail::ShortcutSource Source> KeySelection press(Source &&source, ShortcutOptions options = {}) {
282 return keyActions(std::forward<Source>(source), {KeyAction::PRESS}, options);
283}
284
290inline KeySelection press(std::initializer_list<key::Chord> source, ShortcutOptions options = {}) {
291 return keyActions(source, {KeyAction::PRESS}, options);
292}
293
301template <portals::detail::ShortcutSource Source> KeySelection repeat(Source &&source, ShortcutOptions options = {}) {
302 return keyActions(std::forward<Source>(source), {KeyAction::REPEAT}, options);
303}
304
310inline KeySelection repeat(std::initializer_list<key::Chord> source, ShortcutOptions options = {}) {
311 return keyActions(source, {KeyAction::REPEAT}, options);
312}
313
321template <portals::detail::ShortcutSource Source> KeySelection release(Source &&source, ShortcutOptions options = {}) {
322 return keyActions(std::forward<Source>(source), {KeyAction::RELEASE}, options);
323}
324
330inline KeySelection release(std::initializer_list<key::Chord> source, ShortcutOptions options = {}) {
331 return keyActions(source, {KeyAction::RELEASE}, options);
332}
333
341template <portals::detail::ShortcutSource Source>
342KeySelection pressRepeat(Source &&source, ShortcutOptions options = {}) {
343 return keyActions(std::forward<Source>(source), {KeyAction::PRESS, KeyAction::REPEAT}, options);
344}
345
351inline KeySelection pressRepeat(std::initializer_list<key::Chord> source, ShortcutOptions options = {}) {
352 return keyActions(source, {KeyAction::PRESS, KeyAction::REPEAT}, options);
353}
354
365template <class Callback = detail::QuitCommand>
366 requires portals::detail::ManagedAction<Callback, KeyEvent>
367auto onKey(KeySelection selection, KeyInfo info, Callback callback,
368 std::source_location origin = std::source_location::current()) {
369 return detail::SceneStage{[selection = std::move(selection), info = std::move(info), declaration = detail::retainAction(callback), callback = std::move(callback),
370 origin](Scene &owner) mutable {
371 (void)declaration;
372 owner.onKey(std::move(selection), std::move(info), std::move(callback), origin);
373 }};
374}
375
379template <portals::detail::ShortcutSource Source, class Callback = detail::QuitCommand>
380 requires portals::detail::ManagedAction<Callback, KeyEvent>
381auto onKey(Source &&source, KeyInfo info, Callback callback,
382 std::source_location origin = std::source_location::current()) {
383 return onKey(press(std::forward<Source>(source)), std::move(info), std::move(callback), origin);
384}
385
390template <class Callback = detail::QuitCommand>
391 requires portals::detail::ManagedAction<Callback, KeyEvent>
392auto onKey(KeySelection selection, Callback callback, std::source_location origin = std::source_location::current()) {
393 return detail::SceneStage{
394 [selection = std::move(selection), declaration = detail::retainAction(callback), callback = std::move(callback), origin](Scene &owner) mutable {
395 (void)declaration;
396 detail::SceneAccess::onSelection(owner, selection, callback, origin);
397 }};
398}
399
411template <portals::detail::ShortcutSource Source, class Callback = detail::QuitCommand>
412 requires portals::detail::ManagedAction<Callback, KeyEvent>
413auto onKey(Source &&source, Callback callback, std::source_location origin = std::source_location::current()) {
414 auto shortcut =
415 portals::detail::retainShortcut(portals::detail::prepareShortcut(std::forward<decltype(source)>(source), {}));
416
417 return detail::SceneStage{
418 [shortcut = std::move(shortcut), declaration = detail::retainAction(callback), callback = std::move(callback), origin](Scene &owner) mutable {
419 (void)declaration;
420 detail::SceneAccess::onShortcut(owner, shortcut, callback, {}, {}, origin);
421 }};
422}
423
433template <portals::detail::ShortcutSource Source, class Callback = detail::QuitCommand>
434 requires portals::detail::ManagedAction<Callback, KeyEvent>
435auto onKey(Source &&source, Callback callback, ShortcutBehavior behavior, ShortcutOptions options = {},
436 std::source_location origin = std::source_location::current()) {
437 auto shortcut =
438 portals::detail::retainShortcut(portals::detail::prepareShortcut(std::forward<decltype(source)>(source), options));
439
440 return detail::SceneStage{
441 [shortcut = std::move(shortcut), declaration = detail::retainAction(callback), callback = std::move(callback), behavior, options, origin](Scene &owner) mutable {
442 (void)declaration;
443 detail::SceneAccess::onShortcut(owner, shortcut, callback, behavior, options, origin);
444 }};
445}
446
453template <class Callback = detail::QuitCommand>
454 requires portals::detail::ManagedAction<Callback, KeyEvent>
455auto onKey(std::initializer_list<key::Chord> source, Callback callback,
456 std::source_location origin = std::source_location::current()) {
457 auto shortcut =
458 portals::detail::retainShortcut(portals::detail::prepareShortcut(std::forward<decltype(source)>(source), {}));
459
460 return detail::SceneStage{
461 [shortcut = std::move(shortcut), declaration = detail::retainAction(callback), callback = std::move(callback), origin](Scene &owner) mutable {
462 (void)declaration;
463 detail::SceneAccess::onShortcut(owner, shortcut, callback, {}, {}, origin);
464 }};
465}
466
475template <class Callback = detail::QuitCommand>
476 requires portals::detail::ManagedAction<Callback, KeyEvent>
477auto onKey(std::initializer_list<key::Chord> source, Callback callback, ShortcutBehavior behavior,
478 ShortcutOptions options = {}, std::source_location origin = std::source_location::current()) {
479 auto shortcut =
480 portals::detail::retainShortcut(portals::detail::prepareShortcut(std::forward<decltype(source)>(source), options));
481
482 return detail::SceneStage{
483 [shortcut = std::move(shortcut), declaration = detail::retainAction(callback), callback = std::move(callback), behavior, options, origin](Scene &owner) mutable {
484 (void)declaration;
485 detail::SceneAccess::onShortcut(owner, shortcut, callback, behavior, options, origin);
486 }};
487}
488
499template <class Callback = detail::QuitCommand>
501auto onClick(Ref<Button> reference, Callback callback, std::source_location origin = std::source_location::current()) {
502 return detail::SceneStage{[registration = [reference = std::move(reference), callback = std::move(callback),
503 origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
504 return detail::ClickAccess::attach(scene, reference, std::move(callback), origin);
505 },
506 origin](Scene &owner) mutable {
507 detail::SceneAccess::onClick(owner, registration, origin);
508 }};
509}
510
523template <class T, class Callback>
524 requires(std::derived_from<T, CheckBox> && std::copy_constructible<Callback> &&
525 (portals::detail::ChangeAction<Callback, bool> || portals::detail::ChangeAction<Callback, CheckState>))
526auto onChange(Ref<T> reference, Callback callback, std::source_location origin = std::source_location::current()) {
527 return detail::SceneStage{[registration = [reference = std::move(reference), callback = std::move(callback),
528 origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
529 return detail::ChangeAccess::attach(scene, reference, std::move(callback), origin);
530 },
531 origin](Scene &owner) mutable {
532 detail::SceneAccess::onEditing(owner, registration, origin);
533 }};
534}
535
542template <class T, class Callback>
543 requires((std::derived_from<T, Slider> || std::same_as<T, SpinBox>) && std::copy_constructible<Callback> &&
544 (portals::detail::ChangeValueAction<Callback, double> ||
545 requires(Callback &action, const PropertyUpdate<NumericValue> &receipt) {
546 { action(receipt) } -> portals::detail::ManagedActionResult;
547 }))
548auto onChange(Ref<T> reference, Callback callback, std::source_location origin = std::source_location::current()) {
549 return detail::SceneStage{[registration = [reference = std::move(reference), callback = std::move(callback),
550 origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
551 return detail::ChangeAccess::attach(scene, reference, std::move(callback), origin);
552 },
553 origin](Scene &owner) mutable {
554 detail::SceneAccess::onEditing(owner, registration, origin);
555 }};
556}
557
563template <class T, class Callback>
564 requires(std::same_as<T, RadioGroup> && std::copy_constructible<Callback> &&
565 portals::detail::ChangeAction<Callback, RadioGroupValue>)
566auto onChange(Ref<T> reference, Callback callback, std::source_location origin = std::source_location::current()) {
567 return detail::SceneStage{[registration = [reference = std::move(reference), callback = std::move(callback),
568 origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
569 return detail::ChangeAccess::attach(scene, reference, std::move(callback), origin);
570 },
571 origin](Scene &owner) mutable {
572 detail::SceneAccess::onEditing(owner, registration, origin);
573 }};
574}
575
585template <class Callback>
586 requires portals::detail::ManagedAction<Callback, TextEditedEvent>
587auto onTextEdited(Ref<LineEdit> reference, Callback callback,
588 std::source_location origin = std::source_location::current()) {
589 return detail::SceneStage{[registration = [reference = std::move(reference), callback = std::move(callback),
590 origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
591 return detail::EditorEventAccess::attach<TextEditedEvent>(scene, reference, std::move(callback), origin);
592 },
593 origin](Scene &owner) mutable {
594 detail::SceneAccess::onEditing(owner, registration, origin);
595 }};
596}
597
607template <class Callback, class T>
608 requires(std::derived_from<T, LineEdit> && portals::detail::ManagedAction<Callback, EditingFinishedEvent>)
609auto onEditingFinished(Ref<T> reference, Callback callback,
610 std::source_location origin = std::source_location::current()) {
611 return detail::SceneStage{[registration = [reference = std::move(reference), callback = std::move(callback),
612 origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
613 return detail::EditorEventAccess::attach<EditingFinishedEvent>(scene, reference, std::move(callback), origin);
614 },
615 origin](Scene &owner) mutable {
616 detail::SceneAccess::onEditing(owner, registration, origin);
617 }};
618}
619
626template <class Callback, class T>
627 requires(std::derived_from<T, Slider> && portals::detail::ManagedAction<Callback, SliderOperationEvent>)
628auto onEditingFinished(Ref<T> reference, Callback callback,
629 std::source_location origin = std::source_location::current()) {
630 return detail::SceneStage{[registration = [reference = std::move(reference), callback = std::move(callback),
631 origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
632 return detail::EditorEventAccess::attach<SliderOperationEvent>(scene, reference, std::move(callback), origin);
633 }, origin](Scene &owner) mutable {
634 detail::SceneAccess::onEditing(owner, registration, origin);
635 }};
636}
637
646template <class T, class Callback>
647 requires portals::detail::ManagedAction<Callback, NodeGeometry>
648auto onLayout(Ref<T> reference, Callback callback, std::source_location origin = std::source_location::current()) {
649 return detail::SceneStage{[registration = [reference = std::move(reference), callback = std::move(callback),
650 origin](ManagedScene &scene) mutable -> std::expected<void, ManagedError> {
651 return detail::LayoutAccess::attach(scene, reference, std::move(callback), origin);
652 },
653 origin](Scene &owner) mutable {
654 detail::SceneAccess::onLayout(owner, registration, origin);
655 }};
656}
657
658namespace detail {
662inline std::expected<std::shared_ptr<SceneReportHandler>, ManagedError> pinAppSink(const SceneReportHandler &sink) {
663 try {
664 return sink ? std::make_shared<SceneReportHandler>(sink) : nullptr;
665 } catch (const std::bad_alloc &) {
666 return std::unexpected(ManagedError{ManagedPhase::MOUNT, {}, TreeError::NO_MEMORY, {}, {}});
667 } catch (...) {
668 return std::unexpected(ManagedError{ManagedPhase::MOUNT, {}, TreeError::CALLBACK_FAILED, {}, {}});
669 }
670}
671
681template <AppFactory Factory, AppSetup Setup>
682int runAppFactory(Factory &&factory, Setup &&setup, const RunAppOptions &options,
683 std::shared_ptr<SceneReportHandler> finalSink, std::source_location origin) {
684 FactoryCleanupScope factoryMask;
685 SetupFailureScope invocationScope({}, nullptr, nullptr);
686 CurrentSceneScope currentMask;
687 SceneReportHandler fallbackSink;
688 FactoryCleanup cleanup;
689
690 try {
691 auto description = [&] {
692 FactoryCleanupScope factoryScope(&cleanup);
693
694 return std::invoke(factory);
695 }();
696
697 using Result = std::remove_cvref_t<decltype(description)>;
698 constexpr bool DIRECT_RESULT = IsDescription<Result>::value || std::same_as<Result, Scene>;
699
700 auto create = [&]() {
701 if constexpr (std::same_as<Result, Scene>) {
702 return std::move(description);
703 } else if constexpr (std::same_as<Result, std::expected<Scene, ManagedError>>) {
704 return std::move(*description);
705 } else if constexpr (IsDescription<Result>::value) {
706 return scene(std::move(description), options.scene, origin);
707 } else {
708 return scene(std::move(*description), options.scene, origin);
709 }
710 };
711
712 if constexpr (!DIRECT_RESULT) {
713 if (!description) {
714 reportFactoryFailure(finalSink ? *finalSink : fallbackSink, description.error(), origin, cleanup);
715
716 return 1;
717 }
718 }
719
720 // This owner stays stationary during setup and run; callbacks observe stable State through SceneRef.
721 auto owner = create();
722 auto admitted = SceneAccess::factoryResultChecked(owner);
723
724 if (!admitted) {
725 auto failure = admitted.error();
726 const auto closed = owner.close(origin);
727
728 if (!closed && !failure.cleanup && closed.error().cleanup) {
729 failure.cleanup = closed.error().cleanup;
730 }
731
732 const auto report = factoryFailureReport(std::move(failure), origin, cleanup);
733
734 if (!SceneAccess::deliverFactoryReport(owner, report, finalSink)) {
735 deliverFactoryReport(finalSink ? *finalSink : fallbackSink, report);
736 }
737
738 return 1;
739 }
740
741 const auto droppedErrors = SceneAccess::applyFactoryCleanup(owner, cleanup, origin);
742
743 if (owner.checked()) {
744 std::optional<ManagedError> setupFailure;
745
746 {
747 auto setupScope = SceneAccess::setupScope(owner);
748 auto currentScope = SceneAccess::currentScope(owner);
749
750 try {
751 if constexpr (std::same_as<std::invoke_result_t<Setup &, Scene &>, void>) {
752 std::invoke(setup, owner);
753 } else {
754 auto configured = std::invoke(setup, owner);
755
756 if (!configured) {
757 setupFailure = configured.error();
758 }
759 }
760 } catch (const std::bad_alloc &) {
761 setupFailure = ManagedError{ManagedPhase::BIND, {}, TreeError::NO_MEMORY, {}, {}};
762 } catch (...) {
763 setupFailure = ManagedError{ManagedPhase::BIND, {}, TreeError::CALLBACK_FAILED, {}, {}};
764 }
765 }
766
767 // Finalize the short-error scope before cleanup can revoke its weak delivery publication.
768 if (setupFailure) {
769 SceneAccess::setupFailure(owner, *setupFailure, origin);
770 }
771 }
772
773 return SceneAccess::runApp(owner, options, std::move(finalSink), origin, droppedErrors);
774 } catch (const std::bad_alloc &) {
775 reportFactoryFailure(finalSink ? *finalSink : fallbackSink,
776 ManagedError{ManagedPhase::MOUNT, {}, TreeError::NO_MEMORY, {}, {}}, origin, cleanup);
777 } catch (...) {
778 reportFactoryFailure(finalSink ? *finalSink : fallbackSink,
779 ManagedError{ManagedPhase::MOUNT, {}, TreeError::CALLBACK_FAILED, {}, {}}, origin, cleanup);
780 }
781
782 return 1;
783}
784} // namespace detail
785
804template <detail::AppFactory Factory, detail::AppSetup Setup>
805int runApp(Factory &&factory, Setup &&setup, const RunAppOptions &options = {},
806 std::source_location origin = std::source_location::current()) {
807 detail::FactoryCleanupScope factoryMask;
808 detail::SetupFailureScope invocationScope({}, nullptr, nullptr);
809 detail::CurrentSceneScope currentMask;
810 auto sink = detail::pinAppSink(options.report);
811
812 if (!sink) {
813 detail::reportFactoryFailure({}, sink.error(), origin);
814
815 return 1;
816 }
817
818 return detail::runAppFactory(std::forward<Factory>(factory), std::forward<Setup>(setup), options, std::move(*sink),
819 origin);
820}
821
828template <detail::AppFactory Factory>
829int runApp(Factory &&factory, const RunAppOptions &options = {},
830 std::source_location origin = std::source_location::current()) {
831 return runApp(
832 std::forward<Factory>(factory),
833 [](Scene &) {
834 },
835 options, origin);
836}
837
849template <detail::AppFactory Factory>
850int runApp(Factory &&factory, int argc, const char *const *argv, CommandLineParser parser,
851 const RunAppOptions &options = {}, std::source_location origin = std::source_location::current()) {
852 detail::FactoryCleanupScope factoryMask;
853 detail::SetupFailureScope invocationScope({}, nullptr, nullptr);
854 detail::CurrentSceneScope currentMask;
855 auto sink = detail::pinAppSink(options.report);
856
857 if (!sink) {
858 parser = nullptr;
859 detail::reportFactoryFailure({}, sink.error(), origin);
860
861 return 1;
862 }
863
864 auto action = detail::commandLinePreflight(argc, argv, parser);
865
866 if (!action) {
867 SceneReport report;
868 SceneReportHandler fallbackSink;
869
870 report.origin = origin;
871 report.commandLineFailure = std::move(action.error());
872 detail::deliverFactoryReport(*sink ? **sink : fallbackSink, report);
873
874 return 2;
875 }
876
877 if (action->disposition == LaunchDisposition::FINISH) {
878 if (!action->output.empty()) {
879 std::fwrite(action->output.data(), 1, action->output.size(), stdout);
880 }
881
882 return 0;
883 }
884
885 return detail::runAppFactory(
886 std::forward<Factory>(factory),
887 [](Scene &) {
888 },
889 options, std::move(*sink), origin);
890}
891
892namespace detail {
898template <AppFactory Factory> int operator|(Factory &&factory, RunAppStage stage) {
899 stage.options.terminal = stage.terminal;
900 stage.options.stop = stage.stop;
901
902 return ui::runApp(std::forward<Factory>(factory), stage.options, stage.origin);
903}
904
910template <AppFactory Factory> int operator|(Factory &&factory, CommandLineRunStage stage) {
911 stage.options.terminal = stage.terminal;
912 stage.options.stop = stage.stop;
913
914 return ui::runApp(std::forward<Factory>(factory), stage.argc, stage.argv, std::move(stage.parser), stage.options,
915 stage.origin);
916}
917} // namespace detail
918
923inline auto run(std::stop_token stop = {}, std::source_location origin = std::source_location::current()) {
924 return detail::RunStage{nullptr, stop, origin};
925}
926
932inline auto run(ApplicationTerminal &terminal, std::stop_token stop = {},
933 std::source_location origin = std::source_location::current()) {
934 return detail::RunStage{&terminal, stop, origin};
935}
936
941inline auto runApp(std::stop_token stop = {}, std::source_location origin = std::source_location::current()) {
942 return detail::RunAppStage{nullptr, stop, origin};
943}
944
950inline auto runApp(ApplicationTerminal &terminal, std::stop_token stop = {},
951 std::source_location origin = std::source_location::current()) {
952 return detail::RunAppStage{&terminal, stop, origin};
953}
954
961template <class AppOptions>
962 requires std::same_as<std::remove_cvref_t<AppOptions>, RunAppOptions>
963inline auto runApp(AppOptions &&options, std::source_location origin = std::source_location::current()) {
964 return detail::RunAppStage{options.terminal, options.stop, origin, options};
965}
966
971inline auto applicationOptions(std::function<ApplicationOptions()> callback,
972 std::source_location origin = std::source_location::current()) {
973 return detail::SceneStage{[callback = std::move(callback), origin](Scene &owner) mutable {
974 owner.applicationOptions(std::move(callback), origin);
975 }};
976}
977
984inline auto runApp(int argc, const char *const *argv, CommandLineParser parser,
985 std::source_location origin = std::source_location::current()) {
986 return detail::CommandLineRunStage{argc, argv, std::move(parser), nullptr, {}, origin};
987}
988
996inline auto runApp(ApplicationTerminal &terminal, int argc, const char *const *argv, CommandLineParser parser,
997 std::source_location origin = std::source_location::current()) {
998 return detail::CommandLineRunStage{argc, argv, std::move(parser), &terminal, {}, origin};
999}
1000
1009template <class AppOptions>
1010 requires std::same_as<std::remove_cvref_t<AppOptions>, RunAppOptions>
1011inline auto runApp(int argc, const char *const *argv, CommandLineParser parser, AppOptions &&options,
1012 std::source_location origin = std::source_location::current()) {
1013 return detail::CommandLineRunStage{argc, argv, std::move(parser), options.terminal, options.stop, origin, options};
1014}
1015
1016} // namespace portals::ui
Custom/replay terminal borrowed for exactly one run; no competing I/O is allowed. The owner retains i...
Definition application.hpp:112
One owning callback and its metadata; construct before checked set admission. Captures and metadata c...
Definition ui_action.hpp:75
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
Single-use lazy owner of one Application and ManagedScene; no second runtime. Construct and operate o...
Definition ui_scene.hpp:253
std::expected< ApplicationStats, ManagedError > run(std::stop_token stop={}, std::source_location origin=std::source_location::current())
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()) &
Allocation-free UI execution publication; an empty scope suspends the caller's scene.
Definition current_scene.hpp:37
Stack-only synchronous factory cleanup publication; empty nested scopes suspend attribution.
Definition ui_scene.hpp:165
Allocation-free current-thread setup context; nested independent scopes restore their parent.
Definition setup_failure.hpp:57
Admit callbacks borrowing the mutable chain context, or ordinary no-argument callbacks.
Definition ui_event_access.hpp:141
consteval auto sheet(P values, R... rules)
Definition style_static.hpp:1380
auto reference(ui::Ref< T > value)
Definition ui_static.hpp:572
@ REPEAT
Repeated key press reported by a native adapter.
Definition input.hpp:208
@ RELEASE
Key release reported by a native adapter.
Definition input.hpp:209
@ PRESS
Key press; the only action emitted by the VT decoder.
Definition input.hpp:207
@ MOUNT
Create the scene root or attach and register a managed widget.
Definition managed_diagnostics.hpp:49
@ 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
InputKey
Semantic key identities; character uses KeyEvent::scalar.
Definition input.hpp:64
@ CHARACTER
Character key identified by KeyEvent::scalar; VT uses this for control combinations.
Definition input.hpp:65
@ CALLBACK_FAILED
A user extension or callback threw.
Definition widget_types.hpp:37
@ NO_MEMORY
Allocation failed inside the operation boundary.
Definition widget_types.hpp:33
static KeySelection make(std::expected< Shortcut, ShortcutError > &&shortcut, std::initializer_list< KeyAction > actions, ShortcutOptions options)
Checked factory/setup/run policies.
Definition ui_scene.hpp:145
SceneReportHandler report
Pre-factory sink; nonempty overrides a returned Scene sink, empty preserves it.
Definition ui_scene.hpp:147
Final owning error envelope or bounded successful-run summary; no live widget references.
Definition ui_scene.hpp:27
std::source_location origin
Primary failure call site, or final run call site for a summary.
Definition ui_scene.hpp:29
static std::expected< void, ManagedError > attach(ManagedScene &scene, const Ref< T > &reference, Callback callback, std::source_location origin)
Definition ui_event_access.hpp:112
static std::expected< void, ManagedError > attach(ManagedScene &scene, const Ref< Button > &reference, Callback callback, std::source_location origin)
Definition ui_event_access.hpp:45
Lazy command-line preflight followed by the existing final runner boundary.
Definition ui_scene_pipeline.hpp:122
CommandLineParser parser
Owning parser adapter; bound options remain caller-owned.
Definition ui_scene_pipeline.hpp:125
friend int operator|(Scene &&owner, CommandLineRunStage stage)
Definition ui_scene_pipeline.hpp:149
RunAppOptions options
Pre-factory policies; returned Scene policies remain its own.
Definition ui_scene_pipeline.hpp:129
friend int operator|(Scene &owner, CommandLineRunStage stage)
Definition ui_scene_pipeline.hpp:135
int argc
Input argument count, including program name.
Definition ui_scene_pipeline.hpp:123
std::source_location origin
Final stage call site.
Definition ui_scene_pipeline.hpp:128
ApplicationTerminal * terminal
Optional borrowed custom transport.
Definition ui_scene_pipeline.hpp:126
const char *const * argv
Borrowed input array, copied at consumption.
Definition ui_scene_pipeline.hpp:124
std::stop_token stop
Optional worker-safe cancellation.
Definition ui_scene_pipeline.hpp:127
static std::expected< void, ManagedError > attach(ManagedScene &scene, const Ref< T > &reference, Callback callback, std::source_location origin)
Definition ui_event_access.hpp:82
Allocation-free diagnostics from local scenes abandoned during one factory invocation.
Definition ui_scene.hpp:154
Recognize an owning recipe after cv/ref normalization.
Definition ui_recipe_context.hpp:35
static std::expected< void, ManagedError > attach(ManagedScene &scene, const Ref< T > &reference, Callback callback, std::source_location origin)
Definition ui_event_access.hpp:21
Final int stage over the same runApp boundary; transport remains borrowed.
Definition ui_scene_pipeline.hpp:93
ApplicationTerminal * terminal
Borrowed transport, or null for native terminal ownership.
Definition ui_scene_pipeline.hpp:94
RunAppOptions options
Upper factory policies; callable construction precedes consumption.
Definition ui_scene_pipeline.hpp:97
friend int operator|(Scene &&owner, RunAppStage stage)
Definition ui_scene_pipeline.hpp:116
std::source_location origin
Final stage call site.
Definition ui_scene_pipeline.hpp:96
std::stop_token stop
Optional worker-safe cancellation.
Definition ui_scene_pipeline.hpp:95
friend int operator|(Scene &owner, RunAppStage stage)
Definition ui_scene_pipeline.hpp:103
Terminal pipe adapter; the borrowed transport is optional for native run.
Definition ui_scene_pipeline.hpp:78
std::source_location origin
Pipe registration call site.
Definition ui_scene_pipeline.hpp:81
friend std::expected< ApplicationStats, ManagedError > operator|(Scene owner, RunStage stage)
Definition ui_scene_pipeline.hpp:87
std::stop_token stop
Existing runner cancellation.
Definition ui_scene_pipeline.hpp:80
ApplicationTerminal * terminal
Borrowed transport, or null for the native run overload.
Definition ui_scene_pipeline.hpp:79
static void onLayout(Scene &owner, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1299
static void configure(Scene &owner, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1344
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 bool deliverFactoryReport(Scene &owner, const SceneReport &report, std::shared_ptr< SceneReportHandler > sink)
Definition ui_scene.hpp:1139
static void onKey(Scene &owner, KeyEvent chord, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1356
static void styleLayer(Scene &owner, StyleTier tier, const std::string &name, const StyleSheet &sheet, std::source_location origin)
Definition ui_scene.hpp:1333
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 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 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 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
Owning minimal pipe adapter forwarding to the same facade method.
Definition ui_scene_pipeline.hpp:29
friend Scene operator|(Scene &&input, SceneStage &&stage)
Definition ui_scene_pipeline.hpp:68
Action action
Owning method adapter; explicitly borrowed services remain borrowed.
Definition ui_scene_pipeline.hpp:30
friend Scene & operator|(Scene &owner, SceneStage &&stage)
Definition ui_scene_pipeline.hpp:46
friend Scene operator|(Scene &&input, SceneStage &stage)
Definition ui_scene_pipeline.hpp:56
friend Scene & operator|(Scene &owner, SceneStage &stage)
Definition ui_scene_pipeline.hpp:36