5#include <portals/ui_scene_recipes.hpp>
13inline KeyEvent key(
InputKey value, InputModifiers modifiers = {}) {
21inline KeyEvent character(
char32_t scalar, InputModifiers modifiers = {}) {
57 Scene owner(std::move(input));
69 Scene owner(std::move(input));
117 return owner | stage;
150 return owner | std::move(stage);
159inline auto prepare(std::source_location origin = std::source_location::current()) {
160 return detail::SceneStage{[origin](Scene &owner) {
161 owner.prepare(origin);
169inline auto theme(StyleSheet sheet, std::source_location origin = std::source_location::current()) {
179inline auto styleLayers(StyleLayerOptions options = {}, std::source_location origin = std::source_location::current()) {
181 owner.styleLayers(options, origin);
192inline auto styleLayer(
StyleTier tier, std::string name, StyleSheet sheet,
193 std::source_location origin = std::source_location::current()) {
203inline auto onError(
ManagedErrorHandler observer, std::source_location origin = std::source_location::current()) {
205 owner.onError(std::move(observer), origin);
213inline auto reportOnError(SceneReportHandler sink = {}, std::source_location origin = std::source_location::current()) {
215 owner.reportOnError(std::move(sink), origin);
224template <detail::SceneConfiguration Callback>
225auto configure(Callback callback, std::source_location origin = std::source_location::current()) {
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 {
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);
269inline KeySelection keyActions(std::initializer_list<key::Chord> source, std::initializer_list<KeyAction> actions,
270 ShortcutOptions options = {}) {
281template <portals::detail::ShortcutSource Source> KeySelection press(Source &&source, ShortcutOptions options = {}) {
282 return keyActions(std::forward<Source>(source), {
KeyAction::PRESS}, options);
290inline KeySelection press(std::initializer_list<key::Chord> source, ShortcutOptions options = {}) {
301template <portals::detail::ShortcutSource Source> KeySelection repeat(Source &&source, ShortcutOptions options = {}) {
310inline KeySelection repeat(std::initializer_list<key::Chord> source, ShortcutOptions options = {}) {
321template <portals::detail::ShortcutSource Source> KeySelection release(Source &&source, ShortcutOptions options = {}) {
330inline KeySelection release(std::initializer_list<key::Chord> source, ShortcutOptions options = {}) {
341template <portals::detail::ShortcutSource Source>
342KeySelection pressRepeat(Source &&source, ShortcutOptions options = {}) {
351inline KeySelection pressRepeat(std::initializer_list<key::Chord> source, ShortcutOptions options = {}) {
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 {
372 owner.onKey(std::move(selection), std::move(info), std::move(callback), origin);
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);
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()) {
394 [selection = std::move(selection), declaration = detail::retainAction(callback), callback = std::move(callback), origin](
Scene &owner)
mutable {
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()) {
415 portals::detail::retainShortcut(portals::detail::prepareShortcut(std::forward<
decltype(source)>(source), {}));
418 [shortcut = std::move(shortcut), declaration = detail::retainAction(callback), callback = std::move(callback), origin](
Scene &owner)
mutable {
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()) {
438 portals::detail::retainShortcut(portals::detail::prepareShortcut(std::forward<
decltype(source)>(source), options));
441 [shortcut = std::move(shortcut), declaration = detail::retainAction(callback), callback = std::move(callback), behavior, options, origin](
Scene &owner)
mutable {
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()) {
458 portals::detail::retainShortcut(portals::detail::prepareShortcut(std::forward<
decltype(source)>(source), {}));
461 [shortcut = std::move(shortcut), declaration = detail::retainAction(callback), callback = std::move(callback), origin](
Scene &owner)
mutable {
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()) {
480 portals::detail::retainShortcut(portals::detail::prepareShortcut(std::forward<
decltype(source)>(source), options));
483 [shortcut = std::move(shortcut), declaration = detail::retainAction(callback), callback = std::move(callback), behavior, options, origin](
Scene &owner)
mutable {
499template <
class Callback = detail::QuitCommand>
501auto onClick(
Ref<Button> reference, Callback callback, std::source_location origin = std::source_location::current()) {
503 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
506 origin](
Scene &owner)
mutable {
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()) {
528 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
531 origin](
Scene &owner)
mutable {
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;
548auto onChange(
Ref<T> reference, Callback callback, std::source_location origin = std::source_location::current()) {
550 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
553 origin](
Scene &owner)
mutable {
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()) {
568 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
571 origin](
Scene &owner)
mutable {
585template <
class Callback>
586 requires portals::detail::ManagedAction<Callback, TextEditedEvent>
588 std::source_location origin = std::source_location::current()) {
590 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
593 origin](
Scene &owner)
mutable {
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()) {
612 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
615 origin](
Scene &owner)
mutable {
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()) {
631 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
633 }, origin](
Scene &owner)
mutable {
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()) {
650 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
653 origin](
Scene &owner)
mutable {
662inline std::expected<std::shared_ptr<SceneReportHandler>, ManagedError> pinAppSink(
const SceneReportHandler &sink) {
664 return sink ? std::make_shared<SceneReportHandler>(sink) : nullptr;
665 }
catch (
const std::bad_alloc &) {
681template <AppFactory Factory, AppSetup Setup>
682int runAppFactory(Factory &&factory, Setup &&setup,
const RunAppOptions &options,
683 std::shared_ptr<SceneReportHandler> finalSink, std::source_location origin) {
687 SceneReportHandler fallbackSink;
691 auto description = [&] {
694 return std::invoke(factory);
697 using Result = std::remove_cvref_t<
decltype(description)>;
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);
706 return scene(std::move(description), options.scene, origin);
708 return scene(std::move(*description), options.scene, origin);
712 if constexpr (!DIRECT_RESULT) {
714 reportFactoryFailure(finalSink ? *finalSink : fallbackSink, description.error(), origin, cleanup);
721 auto owner = create();
725 auto failure = admitted.error();
726 const auto closed = owner.close(origin);
728 if (!closed && !failure.cleanup && closed.error().cleanup) {
729 failure.cleanup = closed.error().cleanup;
732 const auto report = factoryFailureReport(std::move(failure), origin, cleanup);
735 deliverFactoryReport(finalSink ? *finalSink : fallbackSink, report);
743 if (owner.checked()) {
744 std::optional<ManagedError> setupFailure;
751 if constexpr (std::same_as<std::invoke_result_t<Setup &, Scene &>,
void>) {
752 std::invoke(setup, owner);
754 auto configured = std::invoke(setup, owner);
757 setupFailure = configured.error();
760 }
catch (
const std::bad_alloc &) {
774 }
catch (
const std::bad_alloc &) {
775 reportFactoryFailure(finalSink ? *finalSink : fallbackSink,
778 reportFactoryFailure(finalSink ? *finalSink : fallbackSink,
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()) {
810 auto sink = detail::pinAppSink(options.report);
813 detail::reportFactoryFailure({}, sink.error(), origin);
818 return detail::runAppFactory(std::forward<Factory>(factory), std::forward<Setup>(setup), options, std::move(*sink),
828template <detail::AppFactory Factory>
829int runApp(Factory &&factory,
const RunAppOptions &options = {},
830 std::source_location origin = std::source_location::current()) {
832 std::forward<Factory>(factory),
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()) {
855 auto sink = detail::pinAppSink(options.report);
859 detail::reportFactoryFailure({}, sink.error(), origin);
864 auto action = detail::commandLinePreflight(argc, argv, parser);
868 SceneReportHandler fallbackSink;
871 report.commandLineFailure = std::move(action.error());
872 detail::deliverFactoryReport(*sink ? **sink : fallbackSink, report);
877 if (action->disposition == LaunchDisposition::FINISH) {
878 if (!action->output.empty()) {
879 std::fwrite(action->output.data(), 1, action->output.size(), stdout);
885 return detail::runAppFactory(
886 std::forward<Factory>(factory),
889 options, std::move(*sink), origin);
898template <AppFactory Factory>
int operator|(Factory &&factory,
RunAppStage stage) {
899 stage.options.terminal = stage.terminal;
900 stage.options.stop = stage.stop;
902 return ui::runApp(std::forward<Factory>(factory), stage.options, stage.origin);
911 stage.options.terminal = stage.terminal;
912 stage.options.stop = stage.stop;
914 return ui::runApp(std::forward<Factory>(factory), stage.argc, stage.argv, std::move(stage.parser), stage.options,
923inline auto run(std::stop_token stop = {}, std::source_location origin = std::source_location::current()) {
932inline auto run(ApplicationTerminal &terminal, std::stop_token stop = {},
933 std::source_location origin = std::source_location::current()) {
941inline auto runApp(std::stop_token stop = {}, std::source_location origin = std::source_location::current()) {
950inline auto runApp(ApplicationTerminal &terminal, std::stop_token stop = {},
951 std::source_location origin = std::source_location::current()) {
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()) {
971inline auto applicationOptions(std::function<ApplicationOptions()> callback,
972 std::source_location origin = std::source_location::current()) {
974 owner.applicationOptions(std::move(callback), origin);
984inline auto runApp(
int argc,
const char *
const *argv, CommandLineParser parser,
985 std::source_location origin = std::source_location::current()) {
996inline auto runApp(ApplicationTerminal &terminal,
int argc,
const char *
const *argv, CommandLineParser parser,
997 std::source_location origin = std::source_location::current()) {
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()) {
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