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>
14namespace portals::ui {
41using SceneReportHandler = std::function<void(
const SceneReport &)>;
48void reportToStderr(
const SceneReport &report)
noexcept;
54template <
class Callback>
56 { callback(scene) } -> std::same_as<void>;
58 { callback(scene) } -> std::same_as<std::expected<void, ManagedError>>;
59} || (!std::invocable<Callback &, ManagedScene &> &&
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>>;
69template <
class Callback>
71 { callback() } -> std::same_as<void>;
72} ||
requires(Callback &callback) {
73 { callback() } -> std::same_as<std::expected<void, ManagedError>>;
82template <
class T>
class Ref;
99 std::expected<void, ManagedError>
quit(std::source_location origin = std::source_location::current())
const;
104 friend struct QuitAction;
106 SceneRef(std::weak_ptr<detail::SceneAnchor> anchor, std::thread::id owner)
107 : anchor_(std::move(anchor)), owner_(owner) {
110 void report(
const ManagedError &failure, std::source_location origin)
const;
111 std::weak_ptr<detail::SceneAnchor> anchor_;
112 std::thread::id owner_{};
134inline QuitAction quit(SceneRef scene, std::source_location origin = std::source_location::current()) {
135 return {std::move(scene), origin};
142void quit(std::source_location origin = std::source_location::current());
188void deliverFactoryReport(const SceneReportHandler &sink, const
SceneReport &report) noexcept;
205void reportFactoryFailure(
const SceneReportHandler &sink,
ManagedError failure, std::source_location origin,
210 const std::thread::id
owner = std::this_thread::get_id();
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>();
228 virtual std::expected<bool, ManagedError>
attach(
ManagedScene &scene,
const std::shared_ptr<SceneAnchor> &anchor) = 0;
240 virtual std::expected<std::shared_ptr<LiveBinding>,
ManagedError>
241 create(
const std::shared_ptr<SceneAnchor> &anchor) = 0;
273 DynamicRef get(std::string_view name, std::source_location origin = std::source_location::current());
281 requires std::derived_from<T, Widget>
282 Ref<T> get(std::string_view name, std::source_location origin = std::source_location::current());
287 Scene &
prepare(std::source_location origin = std::source_location::current()) &;
292 Scene &&
prepare(std::source_location origin = std::source_location::current()) && {
293 static_cast<Scene &
>(*this).prepare(origin);
295 return std::move(*
this);
301 std::expected<void, ManagedError>
prepareChecked(std::source_location origin = std::source_location::current());
303 std::expected<void, ManagedError>
checked()
const;
313 std::expected<ManagedDiagnosticBatch, TreeError>
diagnostics()
const;
326 applyTheme(sheet, origin);
328 return std::move(*
this);
344 std::source_location origin = std::source_location::current()) && {
347 return std::move(*
this);
364 static_cast<Scene &
>(*this).style(stage, origin);
366 return std::move(*
this);
375 template <
class Source>
376 requires std::constructible_from<StyleStage, Source &&, const StyleOptions &, std::source_location>
378 std::source_location origin = std::source_location::current()) &;
386 template <
class Source>
387 requires std::constructible_from<StyleStage, Source &&, const StyleOptions &, std::source_location>
389 std::source_location origin = std::source_location::current()) &&;
400 std::source_location origin = std::source_location::current()) &;
409 std::source_location origin = std::source_location::current()) && {
410 applyStyleLayer(tier, name, sheet, origin);
412 return std::move(*
this);
429 incomingObserver.swap(observer);
430 static_cast<Scene &
>(*this).onError(std::move(incomingObserver), origin);
432 return std::move(*
this);
440 Scene &
reportOnError(SceneReportHandler sink = {}, std::source_location origin = std::source_location::current()) &;
447 std::source_location origin = std::source_location::current()) && {
449 SceneReportHandler incomingSink;
451 incomingSink.swap(sink);
452 static_cast<Scene &
>(*this).reportOnError(std::move(incomingSink), origin);
454 return std::move(*
this);
475 template <detail::SceneConfiguration Callback>
476 Scene &
configure(Callback callback, std::source_location origin = std::source_location::current()) & {
477 configureImpl(callback, origin);
488 template <detail::SceneConfiguration Callback>
489 Scene &&
configure(Callback callback, std::source_location origin = std::source_location::current()) && {
490 configureImpl(callback, origin);
492 return std::move(*
this);
507 template <detail::SceneStop Callback>
508 Scene &
onStop(Callback callback, std::source_location origin = std::source_location::current()) & {
509 stopImpl(callback, origin);
519 template <detail::SceneStop Callback>
520 Scene &&
onStop(Callback callback, std::source_location origin = std::source_location::current()) && {
521 stopImpl(callback, origin);
523 return std::move(*
this);
529 template <
class Info,
class Callback>
532 std::source_location origin = std::source_location::current()) & {
533 onAnnotatedImpl(std::move(selection), std::move(info), callback, origin);
540 template <
class Info,
class 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);
552 template <portals::detail::ShortcutSource Source,
class Info,
class 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);
565 template <portals::detail::ShortcutSource Source,
class Info,
class 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);
579 template <
class Callback = detail::QuitCommand>
582 std::source_location origin = std::source_location::current()) & {
583 onSelectionImpl(selection, callback, origin);
594 template <
class Callback = detail::QuitCommand>
597 std::source_location origin = std::source_location::current()) && {
598 onSelectionImpl(selection, callback, origin);
600 return std::move(*
this);
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);
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);
628 return std::move(*
this);
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);
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);
658 return std::move(*
this);
670 template <portals::detail::ShortcutSource Source,
class Callback = detail::QuitCommand>
673 std::source_location origin = std::source_location::current()) & {
674 onShortcutSourceImpl(std::forward<
decltype(source)>(source), callback, behavior, options, origin);
688 template <portals::detail::ShortcutSource Source,
class Callback = detail::QuitCommand>
691 std::source_location origin = std::source_location::current()) && {
692 onShortcutSourceImpl(std::forward<
decltype(source)>(source), callback, behavior, options, origin);
694 return std::move(*
this);
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);
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);
724 return std::move(*
this);
735 template <
class Callback = detail::QuitCommand>
738 ShortcutOptions options = {}, std::source_location origin = std::source_location::current()) & {
739 onShortcutSourceImpl(std::forward<
decltype(source)>(source), callback, behavior, options, origin);
752 template <
class Callback = detail::QuitCommand>
755 ShortcutOptions options = {}, std::source_location origin = std::source_location::current()) && {
756 onShortcutSourceImpl(std::forward<
decltype(source)>(source), callback, behavior, options, origin);
758 return std::move(*
this);
765 std::expected<ApplicationStats, ManagedError>
run(std::stop_token stop = {},
766 std::source_location origin = std::source_location::current());
773 std::source_location origin = std::source_location::current());
781 std::source_location origin = std::source_location::current());
787 std::expected<ApplicationStep, ManagedError>
step(std::source_location origin = std::source_location::current());
795 std::expected<void, ManagedError>
quit(std::source_location origin = std::source_location::current());
805 int runApp(std::stop_token stop = {}, std::source_location origin = std::source_location::current());
813 std::source_location origin = std::source_location::current());
823 int runApp(
int argc,
const char *
const *argv, CommandLineParser parser, std::stop_token stop = {},
824 std::source_location origin = std::source_location::current());
836 std::stop_token stop = {}, std::source_location origin = std::source_location::current());
844 std::source_location origin = std::source_location::current()) &;
850 std::expected<void, ManagedError>
close(std::source_location origin = std::source_location::current());
854 using Configuration = portals::detail::MoveOnlyFunction<std::expected<void, ManagedError>(
ManagedScene &)>;
855 using Stop = portals::detail::MoveOnlyFunction<std::expected<void, ManagedError>()>;
860 template <detail::SceneConfiguration Callback>
void configureImpl(Callback &callback, std::source_location origin) {
863 if (!admitConfiguration(
false, origin)) {
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);
874 return std::invoke(callback, scene, admittedApplication(scene));
878 if constexpr (std::same_as<
decltype(invoke()),
void>) {
887 }
catch (
const std::bad_alloc &) {
888 configurationException(TreeError::NO_MEMORY, origin);
890 configurationException(TreeError::CALLBACK_FAILED, origin);
894 template <detail::SceneStop Callback>
void stopImpl(Callback &callback, std::source_location origin) {
895 detail::SetupFailureScope scope({},
nullptr,
nullptr);
896 detail::CurrentSceneScope currentMask;
898 if (!admitConfiguration(
false, origin)) {
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);
910 return std::invoke(callback);
914 }
catch (
const std::bad_alloc &) {
915 configurationException(TreeError::NO_MEMORY, origin);
917 configurationException(TreeError::CALLBACK_FAILED, origin);
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)) {
931 [chord, declaration = detail::retainAction(callback),
932 callback = std::move(callback)](ManagedScene &scene)
mutable {
934 return scene.
onKey(chord, std::move(callback));
937 }
catch (
const std::bad_alloc &) {
938 configurationException(TreeError::NO_MEMORY, origin);
940 configurationException(TreeError::CALLBACK_FAILED, origin);
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)) {
952 [selection, info = std::move(info), declaration = detail::retainAction(callback),
953 callback = std::move(callback), origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
955 auto metadata = info.resolve(scene);
957 return std::unexpected(metadata.error());
959 auto result = scene.
onKey(selection, std::move(*metadata), std::move(callback), origin);
960 return result ? std::expected<void, ManagedError>{} : std::unexpected(result.error());
963 }
catch (
const std::bad_alloc &) {
964 configurationException(TreeError::NO_MEMORY, origin);
966 configurationException(TreeError::CALLBACK_FAILED, origin);
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)) {
979 if (!shortcut || !*shortcut) {
980 shortcutConfigurationFailure(shortcut ? ShortcutError{ShortcutErrorKind::INVALID_CHORD, 0} : shortcut.error(),
988 [selection, declaration = detail::retainAction(callback), callback = std::move(callback),
989 origin](ManagedScene &scene)
mutable {
991 return scene.
onKey(selection, std::move(callback), origin);
994 }
catch (
const std::bad_alloc &) {
995 configurationException(TreeError::NO_MEMORY, origin);
997 configurationException(TreeError::CALLBACK_FAILED, origin);
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)) {
1009 auto shortcut = portals::detail::prepareShortcut(std::forward<
decltype(source)>(source), options);
1011 onShortcutImpl(shortcut, callback, behavior, options, origin);
1012 }
catch (
const std::bad_alloc &) {
1013 configurationException(TreeError::NO_MEMORY, origin);
1015 configurationException(TreeError::CALLBACK_FAILED, origin);
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)) {
1028 shortcutConfigurationFailure(shortcut.error(), origin);
1035 [shortcut = std::move(*shortcut), declaration = detail::retainAction(callback), callback = std::move(callback),
1036 behavior, options, origin](ManagedScene &scene)
mutable {
1038 return scene.
onKey(std::move(shortcut), std::move(callback), behavior, options, origin);
1041 }
catch (
const std::bad_alloc &) {
1042 configurationException(TreeError::NO_MEMORY, origin);
1044 configurationException(TreeError::CALLBACK_FAILED, origin);
1048 template <detail::SceneConfiguration Callback>
void onEventImpl(Callback &callback, std::source_location origin) {
1049 if (!admitConfiguration(
true, origin)) {
1054 addConfiguration(std::move(callback),
true, origin);
1055 }
catch (
const std::bad_alloc &) {
1056 configurationException(TreeError::NO_MEMORY, origin);
1058 configurationException(TreeError::CALLBACK_FAILED, origin);
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);
1084 std::thread::id owner_;
1085 std::unique_ptr<State> state_;
1093 return owner.facadeContext();
1103 owner.asyncEnabled_ =
true;
1114 return owner.admitActivity(std::move(activity));
1122 return owner.factoryResultChecked();
1131 return owner.applyFactoryCleanup(cleanup, origin);
1140 return owner.deliverFactoryReport(report, std::move(sink));
1151 std::source_location origin, std::size_t droppedErrors) {
1152 return owner.runAppReported(options, std::move(sink), origin, droppedErrors);
1160 static std::expected<void, ManagedError>
1177 static std::expected<StyleRoleRegistration, ManagedError>
1179 const auto failure = [&](
TreeError cause) {
1182 if (owner.owner_ != std::this_thread::get_id()) {
1185 if (owner.closed_) {
1188 if (!owner.preparing_ || !owner.servicingActivities_ || owner.reporting_ || owner.styling_ || owner.stylesDirty_) {
1191 if (!owner.find(node)) {
1205 static std::expected<StyleRoleRegistration, ManagedError>
1207 std::initializer_list<std::string_view> names) {
1208 if (owner.owner_ != std::this_thread::get_id()) {
1211 if (owner.closed_ || owner.reporting_ || owner.styling_ || owner.stylesDirty_) {
1215 auto replaced = owner.styles_.
replaceRoles(registration, names);
1219 return std::move(*replaced);
1227 std::expected<void, ManagedError> (*callback)(
void *))
noexcept {
1228 owner.closeContext_ = context;
1229 owner.beforeClose_ = callback;
1236 owner.retainCloseFailure();
1243 owner.facade_ = std::move(anchor);
1262 return owner.setupScope(
"scene.setup");
1270 return owner.shortReported(failure);
1278 template <SceneConfiguration Callback>
1279 static void onClick(
Scene &owner, Callback &callback, std::source_location origin) {
1280 owner.onEventImpl(callback, origin);
1288 template <SceneConfiguration Callback>
1289 static void onEditing(
Scene &owner, Callback &callback, std::source_location origin) {
1290 owner.onEventImpl(callback, origin);
1298 template <SceneConfiguration Callback>
1299 static void onLayout(
Scene &owner, Callback &callback, std::source_location origin) {
1300 owner.onEventImpl(callback, origin);
1307 static void live(
Scene &owner, std::shared_ptr<LiveFactory> factory, std::source_location origin) {
1308 owner.applyLiveBinding(std::move(factory), origin);
1316 owner.setupFailure(std::move(failure), origin);
1324 owner.applyTheme(sheet, origin);
1334 std::source_location origin) {
1335 owner.applyStyleLayer(tier, name, sheet, origin);
1343 template <detail::SceneConfiguration Callback>
1344 static void configure(
Scene &owner, Callback &callback, std::source_location origin) {
1345 owner.configureImpl(callback, origin);
1354 template <
class Callback>
1357 owner.onKeyImpl(chord, callback, origin);
1366 template <
class Callback>
1369 std::source_location origin) {
1370 owner.onSelectionImpl(selection, callback, origin);
1381 template <
class Callback>
1383 static void onShortcut(
Scene &owner, std::expected<Shortcut, ShortcutError> &shortcut, Callback &callback,
1385 owner.onShortcutImpl(shortcut, callback, behavior, options, origin);
1396 template <
class Callback>
1400 std::source_location origin) {
1402 std::expected<Shortcut, ShortcutError> failure = std::unexpected(shortcut.error());
1404 owner.onShortcutImpl(failure, callback, behavior, options, origin);
1409 owner.onShortcutSourceImpl(std::move(**shortcut), callback, behavior, options, origin);
1416 return owner.notifyingRunFailure_;
1422 return owner.dialogPrimaryRecorded_;
1430 return owner.runFailureNotified_;
1437 return {owner.errorCount_, owner.droppedErrors_};
1447 return Scene(std::move(recipe), options, origin);
1458inline int runApp(Scene &owner, std::stop_token stop = {},
1459 std::source_location origin = std::source_location::current()) {
1460 return owner.runApp(stop, origin);
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);
1476 requires std::derived_from<T, Widget>
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 ®istration, 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.
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
static bool capturing() 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 ®istration, 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