5#include <portals/ui_description.hpp>
15 std::function<std::expected<PasswordValue, PasswordFailure>()>
24inline std::expected<PasswordOptions, ManagedError> passwordOptions(
const ControlSettings &settings,
27 const auto apply = [](
auto &target,
const auto &value) {
34 options.
limits = controlTextLimits(settings, options.
limits);
35 apply(options.
editMode, settings.editMode);
36 apply(options.
readOnly, settings.readOnly);
44 if (settings.displayMode) {
52 if (settings.text && !settings.text->isEmptyLiteral()) {
57 const bool validDisplay =
59 const bool validPaste =
61 if (!validMode || !validDisplay || !validPaste ||
67 if (settings.placeholder) {
68 auto text = resolver ? settings.placeholder->resolve(policy, resolver, options.
limits)
69 : settings.placeholder->resolve(policy, options.
limits);
74 if (
const auto *cause = std::get_if<TextError>(&
text.error())) {
75 failure.text = *cause;
77 failure.resource = std::get<TextResourceError>(
text.error());
80 return std::unexpected(std::move(failure));
89inline Description<Password> passwordRecipe(std::optional<ManagedState<PasswordValue>> external, PasswordConfig config,
90 bool inherit, TextResolver resolver = {}) {
91 auto model = std::make_shared<ManagedState<PasswordValue>>(external.value_or(ManagedState<PasswordValue>{}));
93 Access::cold<Password>([options = config.options, policy = config.policy, initial = std::move(config.initial),
94 resolver = std::move(resolver), model, external = external.has_value()](
95 ManagedScene &scene, Node<Widget> parent,
96 MountContext &context) mutable -> std::expected<Node<Password>, ManagedError> {
97 const ControlSettings empty;
98 const auto &settings = context.controlSettings ? *context.controlSettings : empty;
99 auto effective = passwordOptions(settings, options, scene.widthPolicy(), resolver, parent);
102 return std::unexpected(effective.error());
104 if (external && initial) {
108 std::expected<PasswordValue, PasswordFailure> value =
110 : std::expected<PasswordValue,
PasswordFailure>(PasswordValue::create({}, effective->securePolicy));
113 return std::unexpected(
114 portals::detail::passwordError(
ManagedPhase::BIND, parent.id(), std::move(value.error())));
117 auto created = scene.state(std::move(*value));
120 return std::unexpected(created.error());
126 return scene.emplace<Password>(parent, *effective, policy);
131 [model, result = std::move(config.result), clipboard = std::move(config.clipboard),
132 validate = std::move(config.validate)](ManagedScene &scene, Node<Password> node,
const ControlSettings &)
mutable {
133 return scene.bind(node, *model, std::move(result), std::move(clipboard), std::move(validate));
141inline Description<Password> password() {
142 return detail::passwordRecipe(std::nullopt, {},
true);
146inline Description<Password> password(PasswordConfig config) {
147 return detail::passwordRecipe(std::nullopt, std::move(config),
false);
151inline Description<Password> password(ManagedState<PasswordValue> model) {
152 return detail::passwordRecipe(model, {},
true);
158inline Description<Password> password(ManagedState<PasswordValue> model, PasswordConfig config) {
159 return detail::passwordRecipe(model, std::move(config),
false);
163inline Description<Password> password(PasswordRef reference) {
164 return password().reference(std::move(reference));
168inline Description<Password> password(PasswordRef reference, PasswordConfig config) {
169 return password(std::move(config)).reference(std::move(reference));
173inline Description<Password> password(PasswordRef reference, ManagedState<PasswordValue> model) {
174 return password(model).reference(std::move(reference));
180inline Description<Password> password(PasswordRef reference, ManagedState<PasswordValue> model, PasswordConfig config) {
181 return password(model, std::move(config)).reference(std::move(reference));
192 requires(std::same_as<T, LineEdit> || std::same_as<T, Password>)
194 return std::move(description).noEcho(modifier.
enabled);
199constexpr NoEchoModifier noEcho(
bool enabled =
true) noexcept {
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Synchronous read-only byte borrow, valid only during its callback.
Definition secure_string.hpp:195
Single-use owning construction recipe; no mounted widget ownership.
Definition ui_description.hpp:48
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
@ NORMAL
Render the draft using its actual grapheme widths; copying and cutting retain normal behavior.
Definition line_edit.hpp:35
@ NO_ECHO
Render no value or selection, with a fixed-origin caret and intrinsic width one; suppress copy/cut.
Definition line_edit.hpp:37
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
constexpr SizePolicy DEFAULT_EDITOR_POLICY
Single-line editors retain one cell even during shortage; text length is not a flex basis.
Definition layout.hpp:50
std::variant< TreeError, TextError, PasswordInputError, SecureStringFailure, PasswordValueAccessFailure< SecureStringFailure >, PasswordValueAccessFailure< TextError >, PasswordValueAccessFailure< std::monostate > > PasswordFailure
Owning original causes, including independently retained callback/cleanup diagnostics.
Definition password.hpp:42
@ NO_ECHO
No value/selection glyphs, intrinsic width one and fixed-origin caret.
Definition password.hpp:13
@ PASSWORD
One ASCII '*' per grapheme; exposes the grapheme count.
Definition password.hpp:12
@ BIND
Register a managed callback, binding or presentation adapter.
Definition managed_diagnostics.hpp:51
constexpr std::size_t MAX_SECRET_BYTES
Hard upper bound for an individual secret, in bytes.
Definition secure_string.hpp:27
@ DISABLED
Consume paste without reading the service or inspecting supplied bytes.
Definition password.hpp:17
@ ENABLED
Accept bounded external plaintext; wipe the owned service payload after copying.
Definition password.hpp:18
@ NATIVE_GUARDED
Dedicated native RW payload surrounded by inaccessible pages.
Definition secure_string.hpp:32
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
@ ON_COMPLETION
Keep a draft until Enter, programmatic activation or focus loss.
Definition line_edit.hpp:29
@ EXPLICIT
Keep a draft until Enter or programmatic activation; focus loss preserves it.
Definition line_edit.hpp:30
@ IMMEDIATE
Publish each semantic-valid text change; invalid intermediate text remains visible.
Definition line_edit.hpp:28
Owning protected-editor policy; no plaintext history, copying or cutting exists.
Definition password.hpp:22
SecureStringOptions securePolicy
Mandatory native encryption and bounded protected storage.
Definition password.hpp:33
std::optional< std::string > placeholder
Public, nonsecret placeholder; never populated from a secret.
Definition password.hpp:32
PasswordDisplayMode displayMode
NO_ECHO reveals no count through layout.
Definition password.hpp:31
PasswordPastePolicy pastePolicy
Clipboard paste requires explicit opt-in.
Definition password.hpp:30
TextLimits limits
Whole UTF-8 value bounds; edits are never truncated.
Definition password.hpp:23
bool readOnly
Block user edits; explicit setValue remains available.
Definition password.hpp:29
WidthPolicy widthPolicy
Unicode measurement policy; masks always use ASCII '*'.
Definition password.hpp:24
EditMode editMode
Publication boundary shared by input and setValue.
Definition password.hpp:28
Secret-free editing outcome; a commit owns only protected immutable snapshots.
Definition password.hpp:60
std::size_t maxBytes
Maximum application bytes, from zero through MAX_SECRET_BYTES.
Definition secure_string.hpp:40
bool lockPages
Require native resident page locking for payload and any key page before copying input.
Definition secure_string.hpp:44
bool excludeFromDumps
Require Linux core-dump exclusion for payload and any key page; unsupported on Windows/WASM.
Definition secure_string.hpp:46
SecureStringStorage storage
Mandatory allocation policy; no implicit platform fallback.
Definition secure_string.hpp:42
bool encryptWhileIdle
Require native idle encryption; true by default, unsupported with WIPE_ONLY or on WASM.
Definition secure_string.hpp:48
Owning independent policies for width and height.
Definition layout.hpp:35
Owning deterministic width policy; no font or terminal matching promise.
Definition text.hpp:42
Owning cold presentation modifier; ordinary LineEdit storage remains plaintext.
Definition ui_password_controls.hpp:185
bool enabled
False restores each editor type's normal presentation.
Definition ui_password_controls.hpp:186
Optional protected-editor customization; ordinary forms need only password(ref).
Definition ui_password_controls.hpp:12
std::shared_ptr< Clipboard > clipboard
Service used only by explicit ENABLED paste policy.
Definition ui_password_controls.hpp:18
SizePolicy policy
Owning external layout constraints.
Definition ui_password_controls.hpp:14
std::function< std::expected< PasswordValue, PasswordFailure >()> initial
Checked owning provider, called once at mount.
Definition ui_password_controls.hpp:16
std::function< std::expected< void, TreeError >(PasswordResult)> result
Optional secret-free result observer.
Definition ui_password_controls.hpp:17
std::function< bool(SecretView)> validate
Synchronous scoped publication predicate; false retains the draft.
Definition ui_password_controls.hpp:19
PasswordOptions options
Native editor policy; the scene supplies its Unicode width policy.
Definition ui_password_controls.hpp:13
static Description< T > controlSetup(Description< T > description, Callback callback)
Attach binding setup after node creation within the mount transaction.
Definition ui_description.hpp:3460
static Description< T > configuredControl(Description< T > description, std::string_view type, bool inherit=true)
Attach a builtin configuration identity to an owning recipe.
Definition ui_description.hpp:3409
Stack-owned transaction bookkeeping, discarded after one description mount.
Definition ui_recipe_context.hpp:554