5#include <portals/detail/dialog_command_result.hpp>
6#include <portals/scheduler.hpp>
7#include <portals/text_value.hpp>
11struct NotificationRecord;
13enum class ToastCommand {
98 std::function<std::expected<std::string, TextResourceError>(std::string_view)>
105 std::optional<ToastId>
id;
121 std::shared_ptr<const ToastData>
data;
127 std::shared_ptr<const ToastData>
data;
138 std::vector<ToastSnapshot>
items = std::vector<ToastSnapshot>(0);
147struct NotificationTarget;
148struct NotificationAccess;
151concept ToastActionResult = std::same_as<T, void> || std::same_as<T, std::expected<void, TreeError>>;
152template <
class Callback>
154 std::copy_constructible<Callback> && (
requires(Callback &callback,
const ToastActionEvent &event) {
155 { callback(event) } -> ToastActionResult;
156 } || (!std::invocable<Callback &, const ToastActionEvent &> &&
requires(Callback &callback) {
157 { callback() } -> ToastActionResult;
173 return std::move(*
this);
180 return std::move(*
this);
187 return std::move(*
this);
194 return std::move(*
this);
202 template <
class Callback>
203 requires detail::ToastAction<Callback>
205 label_.emplace(std::move(label));
207 action_ = std::make_shared<Action>(
208 [callback = std::move(callback)](
209 [[maybe_unused]]
const ToastActionEvent &event)
mutable -> std::expected<void, TreeError> {
210 const auto invoke = [&]() ->
decltype(
auto) {
211 if constexpr (std::invocable<Callback &, const ToastActionEvent &>) {
212 return callback(event);
218 static_assert(std::same_as<
decltype(invoke()),
void> ||
219 std::same_as<
decltype(invoke()), std::expected<void, TreeError>>);
221 if constexpr (std::same_as<
decltype(invoke()),
void>) {
230 return std::move(*
this);
237 template <
class Callback>
238 requires detail::ToastAction<Callback>
240 return std::move(*this).action(
TextValue(label), std::move(callback));
244 friend struct detail::NotificationAccess;
249 std::optional<TextValue> label_;
250 std::shared_ptr<Action> action_;
259inline ToastMessage toast(std::string_view text, ToastOptions options = {}) {
271 return std::move(message).info();
273 return std::move(message).success();
275 return std::move(message).warning();
277 return std::move(message).error();
280 return std::move(message);
285inline ToastSeverityModifier info() {
322 std::expected<ToastPostReceipt, ManagedError>
323 post(
const ToastMessage &message, std::source_location origin = std::source_location::current())
const;
328 std::source_location origin = std::source_location::current())
const;
351 std::source_location origin = std::source_location::current())
const;
356 friend struct detail::NotificationAccess;
357 std::shared_ptr<detail::NotificationTarget> target_;
362struct NotificationAccess {
366 const std::shared_ptr<portals::detail::NotificationRecord> &record)
noexcept;
367 static std::expected<std::shared_ptr<portals::detail::NotificationRecord>,
ManagedError>
371 std::source_location origin)
noexcept;
373 std::optional<ToastId>
id,
bool flag, std::source_location origin);
Owning validated UTF-8 and immutable extended grapheme measurements.
Definition text.hpp:145
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Owning literal bytes or a resource key, measured only at resolution.
Definition text_value.hpp:42
constexpr TextValue(const TextValue &other)=default
Copy expression bytes and kind into independent storage.
One owning callback and its metadata; construct before checked set admission. Captures and metadata c...
Definition ui_action.hpp:75
Owning checked command that also permits the admitted short callback form. This is a narrow facade re...
Definition dialog_command_result.hpp:20
Copyable weak UI-affine semantic handle; the scene owns all queue, action and timer storage....
Definition toast.hpp:311
DialogCommandResult setVisible(bool visible, std::source_location origin=std::source_location::current()) const
DialogCommandResult show(const ToastMessage &message, std::source_location origin=std::source_location::current()) const
DialogCommandResult show(const TextValue &text, std::source_location origin=std::source_location::current()) const
DialogCommandResult clear(std::source_location origin=std::source_location::current()) const
DialogCommandResult show(std::string_view text, std::source_location origin=std::source_location::current()) const
std::expected< ToastPostReceipt, ManagedError > post(const ToastMessage &message, std::source_location origin=std::source_location::current()) const
NotificationCenter()
Construct an unpublished observing handle on the UI thread; may allocate.
DialogCommandResult activate(ToastId id, std::source_location origin=std::source_location::current()) const
DialogCommandResult dismissLatest(std::source_location origin=std::source_location::current()) const
std::expected< std::shared_ptr< const NotificationSnapshot >, ManagedError > snapshot() const
DialogCommandResult dismiss(ToastId id, std::source_location origin=std::source_location::current()) const
DialogCommandResult activateLatest(std::source_location origin=std::source_location::current()) const
DialogCommandResult setReducedMotion(bool reduced, std::source_location origin=std::source_location::current()) const
Owning UI-only request builder; borrowed callback captures remain the caller's responsibility.
Definition toast.hpp:163
ToastMessage && success() &&
Definition toast.hpp:177
ToastMessage && error() &&
Definition toast.hpp:191
ToastMessage && warning() &&
Definition toast.hpp:184
ToastMessage && action(TextValue label, Callback callback) &&
Definition toast.hpp:204
ToastMessage && action(std::string_view label, Callback callback) &&
Definition toast.hpp:239
ToastMessage && info() &&
Definition toast.hpp:170
ToastMessage(TextValue text, ToastOptions options={})
Definition toast.hpp:166
Public Portals API.
Definition action.hpp:8
ui::ValueText text(std::format_string< const ui::detail::TextArgumentValue< Args > &... > pattern, Args &&...args)
Declare live formatted text over explicit scalar roots, fields or value properties.
Definition ui_value_text.hpp:567
ToastOverflowPolicy
Policy when the total retained-record budget is full.
Definition toast.hpp:44
@ REJECT_NEW
Fail with NODE_LIMIT without changing the queue.
Definition toast.hpp:46
@ DROP_OLDEST_PENDING
Evict the oldest eligible queued transient, otherwise drop the new request.
Definition toast.hpp:45
@ ACTIVATE
Activate the target's primary command.
Definition action.hpp:11
@ CLEAR
Replace a live value with an empty value under the same policy.
Definition secure_string.hpp:74
ToastPlacement
Corner of the owning content viewport.
Definition toast.hpp:37
@ BOTTOM_START
Lower left corner.
Definition toast.hpp:40
@ BOTTOM_END
Lower right corner.
Definition toast.hpp:38
@ TOP_END
Upper right corner.
Definition toast.hpp:39
@ TOP_START
Upper left corner.
Definition toast.hpp:41
ToastPostStatus
Logical admission result; visibility does not acknowledge terminal output.
Definition toast.hpp:30
@ ACCEPTED_VISIBLE
Selected within the logical visible cap; may still be clipped.
Definition toast.hpp:31
@ DROPPED
Successful intentional overflow outcome, without an adopted identity.
Definition toast.hpp:34
@ ACCEPTED_QUEUED
Retained behind the selected FIFO prefix.
Definition toast.hpp:32
@ DEDUPLICATED
Existing identity, payload and action retained.
Definition toast.hpp:33
ToastSeverity
Notification meaning, independent of persistence or application error policy.
Definition toast.hpp:23
@ WARNING
Application warning, represented by !.
Definition toast.hpp:26
@ FAILURE
Application failure, represented by x; does not intercept runtime errors.
Definition toast.hpp:27
@ INFO
Informational message, represented by i in monochrome.
Definition toast.hpp:24
@ SUCCESS
Successful application operation, represented by +.
Definition toast.hpp:25
std::uint64_t SchedulerTime
Monotonic milliseconds; the clock must not move backwards.
Definition scheduler.hpp:18
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
Owning identity, independent of addresses; zero is never a live identity.
Definition widget_types.hpp:15
Fixed host budgets and explicit localization; no borrowed option spans.
Definition toast.hpp:81
std::size_t dedupKeyBytes
Positive deduplication-key byte cap.
Definition toast.hpp:96
ToastOverflowPolicy overflow
Never evict visible, persistent or running actions.
Definition toast.hpp:90
std::int32_t gap
Nonnegative row separation, clamped to the viewport.
Definition toast.hpp:89
std::function< std::expected< std::string, TextResourceError >(std::string_view)> textResolver
UI-only explicit owning resolver.
Definition toast.hpp:99
std::int32_t maximumWidth
Positive width cap in terminal cells.
Definition toast.hpp:87
std::size_t capacity
Positive total budget including selected records.
Definition toast.hpp:84
bool refreshDeduplicated
Refresh only an existing, previously presented transient deadline.
Definition toast.hpp:92
ToastPlacement placement
Corner for retained row placement.
Definition toast.hpp:86
TextLimits textLimits
Full resolved message validation caps.
Definition toast.hpp:94
std::size_t actionLabelBytes
Positive action-label byte cap.
Definition toast.hpp:95
std::size_t maxPaintCells
Positive per-card allocated paint-area cap.
Definition toast.hpp:97
bool reducedMotion
Retain static indicators while disabling alternation.
Definition toast.hpp:93
~NotificationOptions()=default
Retain ordinary fallible copies of owning resolver storage.
std::size_t maxVisible
Logical selection cap in [1, capacity].
Definition toast.hpp:85
std::int32_t margin
Nonnegative viewport inset, clamped at tiny extents.
Definition toast.hpp:88
Independent bounded queue snapshot with saturating policy counters.
Definition toast.hpp:135
std::uint64_t evicted
Pending transient overflow victims.
Definition toast.hpp:140
bool reducedMotion
Explicit center effect policy.
Definition toast.hpp:142
bool visible
Explicit center visibility policy.
Definition toast.hpp:141
std::uint64_t dropped
Intentionally rejected new messages.
Definition toast.hpp:139
std::vector< ToastSnapshot > items
FIFO records without UI callbacks.
Definition toast.hpp:138
~NotificationSnapshot()=default
Keep checked vector transfers fallible on the MSVC debug standard library.
Owning RGB color; terminal encoding belongs to the output adapter.
Definition cell_buffer.hpp:20
Owning limits checked without silently truncating input or clusters.
Definition text.hpp:57
Original action identity and owning immutable data, safe after subtree removal.
Definition toast.hpp:119
ToastId id
Exact notification admitted for this invocation.
Definition toast.hpp:120
std::shared_ptr< const ToastData > data
Message lifetime independent of the removed row.
Definition toast.hpp:121
Immutable owning payload, independent of callback and scene lifetimes.
Definition toast.hpp:110
ToastSeverity severity
Owning semantic severity.
Definition toast.hpp:115
std::optional< GraphemeText > actionLabel
Complete action caption, if any; no callable is exposed.
Definition toast.hpp:114
~ToastData()=default
Keep validated owning-text copies fallible rather than introducing noexcept transfers.
GraphemeText text
Complete validated message, including undisplayed logical lines.
Definition toast.hpp:113
Original center identity and never-reused record sequence.
Definition toast.hpp:50
std::uint64_t sequence
Nonzero monotonically increasing center-local identity.
Definition toast.hpp:52
bool operator==(const ToastId &other) const noexcept=default
NodeId center
Complete session, slot and generation of the owning layer.
Definition toast.hpp:51
Optional static or alternating one-cell diagnostic decoration.
Definition toast.hpp:58
~ToastIndicatorOptions()=default
Keep checked string copies fallible on the MSVC debug standard library.
bool enabled
Keep the ordinary presentation free of an indicator by default.
Definition toast.hpp:61
TextValue glyph
Exactly one grapheme occupying one cell under the scene policy.
Definition toast.hpp:62
RgbColor foreground
Manual foreground beneath theme overrides.
Definition toast.hpp:64
bool alternateBackground
Opt in to the bounded indicator effect.
Definition toast.hpp:63
SchedulerTime period
Positive milliseconds between phase changes when enabled.
Definition toast.hpp:66
RgbColor alertBackground
Alternate background beneath theme overrides.
Definition toast.hpp:65
Owning notification request settings; copying may allocate.
Definition toast.hpp:70
ToastSeverity severity
Readable semantic severity.
Definition toast.hpp:73
std::string dedupKey
Exact case-sensitive bytes; empty disables deduplication.
Definition toast.hpp:75
bool dismissOnAction
Remove before entering the admitted action.
Definition toast.hpp:76
std::optional< SchedulerTime > duration
Positive milliseconds after first presentation; null is persistent.
Definition toast.hpp:74
~ToastOptions()=default
Keep checked string copies fallible on the MSVC debug standard library.
ToastIndicatorOptions indicator
Optional presentation only; no diagnostic interception.
Definition toast.hpp:77
Allocation-free queue admission receipt.
Definition toast.hpp:103
std::optional< ToastId > id
Original retained identity; absent for DROPPED.
Definition toast.hpp:105
ToastPostStatus status
Selected, queued, duplicate or intentionally dropped.
Definition toast.hpp:104
std::optional< ToastId > evictedId
Exact pending transient evicted by committed overflow policy.
Definition toast.hpp:106
Owning record observation; no callback or scene references.
Definition toast.hpp:125
std::shared_ptr< const ToastData > data
Full immutable payload.
Definition toast.hpp:127
ToastId id
Original center and record identity.
Definition toast.hpp:126
bool firstPresented
At least one successful final frame had positive clipped cells.
Definition toast.hpp:130
std::optional< SchedulerTime > deadline
Absolute expiry, absent until first presentation or for persistence.
Definition toast.hpp:131
ToastPostStatus status
Current logical selection, independent of clipping.
Definition toast.hpp:128
std::optional< CellRect > rectangle
Last final arranged surface rectangle when assigned.
Definition toast.hpp:129
Presentation-only severity stage; retains all other owning request policy.
Definition toast.hpp:264
ToastSeverity severity
Existing presentation role.
Definition toast.hpp:265
friend ToastMessage operator|(ToastMessage &&message, ToastSeverityModifier modifier)
Definition toast.hpp:268