5#include <portals/managed.hpp>
12 std::string
caption = std::string(0,
'\0');
14 std::string
help = std::string(0,
'\0');
43struct MenuRegistration;
50 static std::expected<void, ManagedError> attach(
ManagedScene &,
const ActionRef &);
55 static std::expected<void, ManagedError> stageMenu(
ManagedScene &, MenuRegistration &);
56 static std::expected<void, ManagedError> validateMenu(
ManagedScene &,
const MenuRegistration &);
57 static void rollbackMenu(
ManagedScene &,
const MenuRegistration &);
59 static std::expected<void, TreeError> prepare(
ManagedScene &);
61 static EditorCommandResult invoke(
const ActionRef &, ActionInvocation, std::source_location);
62 static EditorCommandResult report(
const ActionRef &, std::expected<void, TreeError>, std::source_location);
63 static std::expected<void, TreeError> live(
const ActionStore &);
64 static std::expected<void, TreeError> dirty(
const ActionStore &);
65 static std::expected<void, TreeError> write(
const ActionStore &);
66 static std::shared_ptr<ActionStore> retain(
const ActionRef &);
77 using Result = std::variant<std::expected<void, TreeError>, std::expected<void, ManagedError>,
84 template <
class CallbackType>
89 const auto invoke = [&]() ->
decltype(
auto) {
90 if constexpr (std::invocable<CallbackType &, const ActionInvocation &>) {
97 if constexpr (std::same_as<
decltype(invoke()),
void>) {
100 return std::expected<void, TreeError>{};
102 std::same_as<
decltype(invoke()), std::expected<void, ManagedError>>) {
105 auto result = invoke();
107 return result ? std::expected<void, TreeError>{} : std::unexpected(result.error());
141 std::source_location origin = std::source_location::current())
const;
148 friend class ActionSet;
149 friend struct detail::ActionAccess;
150 std::expected<std::shared_ptr<detail::ActionRecord>,
TreeError> lock()
const;
151 std::weak_ptr<detail::ActionStore> store_;
152 std::weak_ptr<detail::ActionRecord> record_;
153 std::thread::id owner_{};
154 std::optional<TreeError> failure_;
188 template <
class Callback = detail::QuitCommand>
196 return action(key,
Action{std::move(metadata), std::move(callback)});
197 }
catch (
const std::bad_alloc &) {
207 template <
class Callback = detail::QuitCommand>
209 std::expected<ActionRef, TreeError>
add(std::string_view key, std::string_view caption, Callback callback) {
215 return add(key,
Action{std::move(metadata), std::move(callback)});
216 }
catch (
const std::bad_alloc &) {
225 std::shared_ptr<detail::ActionStore> store_;
231template <
class Callback>
auto retainAction(
const Callback &callback) {
232 if constexpr (std::same_as<Callback, ActionRef>) {
233 return ActionAccess::retain(callback);
235 return std::monostate{};
Owning checked editor command, preserving exactly its collector reporting receipt....
Definition editor_command.hpp:23
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
Weak UI-affine action identity; owner retirement never leaves an executable callback.
Definition ui_action.hpp:117
EditorCommandResult rebind(Action action, std::source_location origin=std::source_location::current()) const
ActionRef()=default
Empty weak identity; operations return CLOSED.
EditorCommandResult remove(std::source_location origin=std::source_location::current()) const
EditorCommandResult operator()(const ClickEvent &event) const
EditorCommandResult invoke(ActionInvocation invocation={}, std::source_location origin=std::source_location::current()) const
EditorCommandResult set(ActionMetadata metadata, std::source_location origin=std::source_location::current()) const
std::expected< std::shared_ptr< const ActionMetadata >, TreeError > snapshot() const
EditorCommandResult operator()(const KeyEvent &event) const
std::expected< ActionRef, TreeError > add(std::string_view key, std::string_view caption, Callback callback)
Definition ui_action.hpp:209
ActionSet & operator=(ActionSet &&other) noexcept
ActionSet(ActionSetOptions options={})
ActionRef action(std::string_view key, Action action)
ActionRef action(std::string_view key, std::string_view caption, Callback callback)
Definition ui_action.hpp:190
~ActionSet()
Release cold declarations on UI; attached scenes/recipes retain their own ownership.
std::expected< ActionRef, TreeError > add(std::string_view key, Action action)
ActionSet(ActionSet &&other) noexcept
One owning callback and its metadata; construct before checked set admission. Captures and metadata c...
Definition ui_action.hpp:75
std::function< Result(const ActionInvocation &)> Callback
Owning compact callback adapter.
Definition ui_action.hpp:79
ActionMetadata metadata
Owning metadata admitted with the callback.
Definition ui_action.hpp:112
std::variant< std::expected< void, TreeError >, std::expected< void, ManagedError >, EditorCommandResult > Result
Exact callback outcome.
Definition ui_action.hpp:77
Action(ActionMetadata metadata, CallbackType callback)
Definition ui_action.hpp:86
Callback callback
Single owning callback; admitted invocations pin this object.
Definition ui_action.hpp:113
A compact action optionally receives owning event parameters.
Definition managed.hpp:239
EventReply
Explicit bubbling decision; ignored continues toward the original root.
Definition action.hpp:49
std::variant< ActionEvent, KeyEvent, TextInputEvent, PasteInputEvent, MouseInputEvent > RoutedEvent
Synchronous input value; callback borrows it only until return.
Definition action.hpp:47
ClickSource
Origin of an admitted activation, without inferred physical input.
Definition action.hpp:24
@ PROGRAMMATIC
Explicit semantic action, the default for caller-created ActionEvent.
Definition action.hpp:25
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
@ 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
Owning activation parameters copied from the existing router delivery. target is the activated button...
Definition controls.hpp:204
Owning key value without an inferred physical keyboard scan code.
Definition input.hpp:213
Owning synchronous invocation context; no widget or scene ownership.
Definition ui_action.hpp:30
ClickSource source
Original explicit, keyboard or pointer source.
Definition ui_action.hpp:31
InputModifiers modifiers
Original input intent where supplied.
Definition ui_action.hpp:32
Positive finite admission budgets for one owning set.
Definition ui_action.hpp:22
std::size_t maxActions
Live action count.
Definition ui_action.hpp:23
std::size_t maxPresenters
Live button projections and menu entries, including duplicates.
Definition ui_action.hpp:24
std::size_t maxMetadataBytes
Live keys/current metadata; external snapshots are independent.
Definition ui_action.hpp:25
std::size_t maxKeyBytes
Per-action key byte limit.
Definition ui_action.hpp:26