Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
password.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/detail/text_metadata.hpp>
6#include <portals/line_edit.hpp>
7#include <portals/password_value.hpp>
8
9namespace portals {
15
20
35
40
45
58
62 std::optional<PropertyUpdate<PasswordValue>> commit;
63 std::optional<PasswordFailure> failure;
65 std::optional<TreeError> callbackError;
66};
67
74class Password final : public SizedWidget {
75public:
81 explicit Password(PasswordOptions options = {}, SizePolicy policy = DEFAULT_EDITOR_POLICY);
85 std::expected<CellSize, TreeError> measure(CellSize available) override;
89 std::expected<void, TreeError> arrange(CellRect local) override;
93 std::expected<void, TreeError> paint(PaintContext &context) override;
95 std::size_t cursor() const noexcept;
97 std::size_t anchor() const noexcept;
99 bool dirty() const noexcept;
101 ComputedStyle styleDefaults() const override;
102
103private:
104 friend class PasswordBinding;
105 friend class ManagedScene;
106 friend struct ui::detail::RefAccess;
107 std::int32_t cellAt(std::size_t byte) const noexcept;
108 void revealCursor() noexcept;
109 PasswordOptions options_;
110 PasswordValue draft_;
111 detail::TextMetadata metadata_;
112 std::unique_ptr<GraphemeText> masked_;
113 std::unique_ptr<GraphemeText> placeholder_;
114 CellRect bounds_;
115 std::size_t cursor_{};
116 std::size_t anchor_{};
117 std::int32_t scroll_{};
118 bool dirty_{};
119 bool focused_{};
120 bool enabled_{true};
121};
122
129public:
138 PasswordBinding(const PasswordBinding &) = delete;
139 PasswordBinding &operator=(const PasswordBinding &) = delete;
143 std::expected<void, PasswordFailure> sync(Node<Widget> focused);
148 std::expected<PasswordResult, PasswordFailure> confirm();
153 std::expected<PasswordResult, PasswordFailure> cancel();
159 std::expected<PasswordResult, PasswordFailure> setValue(PasswordValue value);
160
161private:
162 struct State;
163 friend class ManagedScene;
164 friend struct ui::detail::RefAccess;
165 friend std::expected<PasswordBinding, PasswordFailure>
167 std::function<void(PasswordResult)>, std::shared_ptr<Clipboard>, std::function<bool(SecretView)>);
168 PasswordBinding(std::shared_ptr<State> state, ActionBinding action, Subscription subscription);
169 std::shared_ptr<State> state_;
170 ActionBinding action_;
171 Subscription subscription_;
172};
173
184std::expected<PasswordBinding, PasswordFailure> bindPassword(WidgetTree &tree, EventRouter &router, Node<Password> node,
185 std::shared_ptr<Property<PasswordValue>> model,
186 std::function<void(PasswordResult)> onResult,
187 std::shared_ptr<Clipboard> clipboard = {},
188 std::function<bool(SecretView)> validate = {});
189} // namespace portals
Move-only scoped disconnect token; never owns a tree or widget. Disconnect/destruction may run on any...
Definition action.hpp:96
An owning, invariant-preserving half-open cell rectangle.
Definition geometry.hpp:81
UI-owned focus and synchronous bubbling over an existing WidgetTree. Tree and Scheduler must outlive ...
Definition action.hpp:169
Owning validated UTF-8 and immutable extended grapheme measurements.
Definition text.hpp:145
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Borrowed synchronous command sink supplied by the frame owner. submit must consume commands immediate...
Definition widget_types.hpp:66
std::expected< PasswordResult, PasswordFailure > cancel()
std::expected< void, PasswordFailure > sync(Node< Widget > focused)
PasswordBinding & operator=(PasswordBinding &&other) noexcept
PasswordBinding(PasswordBinding &&other) noexcept
friend std::expected< PasswordBinding, PasswordFailure > bindPassword(WidgetTree &, EventRouter &, Node< Password >, std::shared_ptr< Property< PasswordValue > >, std::function< void(PasswordResult)>, std::shared_ptr< Clipboard >, std::function< bool(SecretView)>)
Bind and securely inspect the initial model before publishing presentation.
std::expected< PasswordResult, PasswordFailure > confirm()
~PasswordBinding()
Disconnect future actions/subscriptions; admitted callbacks retain owners.
std::expected< PasswordResult, PasswordFailure > setValue(PasswordValue value)
Copyable identity of immutable logical bytes in protected native storage.
Definition password_value.hpp:44
std::expected< void, TreeError > arrange(CellRect local) override
std::size_t anchor() const noexcept
std::expected< void, TreeError > paint(PaintContext &context) override
Password(PasswordOptions options={}, SizePolicy policy=DEFAULT_EDITOR_POLICY)
Construct an unbound empty presentation.
ComputedStyle styleDefaults() const override
bool dirty() const noexcept
std::size_t cursor() const noexcept
std::expected< CellSize, TreeError > measure(CellSize available) override
UI-owned typed value with node-scoped observers and explicit partial delivery. WidgetTree and its Sch...
Definition property.hpp:62
Synchronous read-only byte borrow, valid only during its callback.
Definition secure_string.hpp:195
SizedWidget(SizePolicy policy={})
Own the supplied policies; checked by layout.
UI-owned move-only cancellation token. Release before Scheduler. Disconnect is immediate logically; a...
Definition scheduler.hpp:121
Exclusive parent/child ownership on Scheduler's UI thread. Scheduler must outlive this object....
Definition widget.hpp:179
Public Portals API.
Definition action.hpp:8
@ NO_ECHO
Render no value or selection, with a fixed-origin caret and intrinsic width one; suppress copy/cut.
Definition line_edit.hpp:37
@ PASSWORD
Render one ASCII '*' per grapheme, revealing its count; suppress outbound copy/cut.
Definition line_edit.hpp:36
PasswordStatus
Outcome of a protected edit or publication boundary.
Definition password.hpp:47
@ EDITED
Accepted local protected draft, selection change or no-op.
Definition password.hpp:48
@ DISABLED
Recording is stopped; retained evidence remains available.
Definition diagnostics.hpp:72
@ ENABLED
Ring admission is active.
Definition diagnostics.hpp:73
@ FAILED
The coroutine returned an error or threw.
Definition async.hpp:46
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
@ INVALID_TEXT
Projected row is not admitted UTF-8 under the scene text policy.
Definition find_bar.hpp:53
@ CANCELLED
Explicit cancellation or replacement stopped the invocation.
Definition async.hpp:29
@ LIMIT_EXCEEDED
A storage request cannot fit its configured aggregate budget.
Definition background_options.hpp:19
@ CLIPBOARD_FAILED
The injected service was absent or rejected the operation.
Definition line_edit.hpp:90
@ COMMITTED
Confirmation completed Property::set; inspect its exact receipt.
Definition line_edit.hpp:83
@ EDITED
A local draft or selection changed.
Definition line_edit.hpp:82
@ VALIDATION_FAILED
The commit validator rejected the complete draft.
Definition line_edit.hpp:89
@ CONFLICT
The model revision changed since this draft began.
Definition line_edit.hpp:86
PasswordDisplayMode
Constant-glyph presentation of protected editor values.
Definition password.hpp:11
@ PASSWORD
One ASCII '*' per grapheme; exposes the grapheme count.
Definition password.hpp:12
PasswordInputError
Protected editor input rules beyond UTF-8 validity.
Definition password.hpp:37
@ LINE_SEPARATOR
Valid Unicode contains CR, LF, LINE SEPARATOR or PARAGRAPH SEPARATOR.
Definition password.hpp:38
PasswordPastePolicy
Explicit admission of plaintext supplied by the system clipboard/input decoder.
Definition password.hpp:16
@ DISABLED
Consume paste without reading the service or inspecting supplied bytes.
Definition password.hpp:17
LineEditTrigger
Entry path that produced an editing or confirmation outcome.
Definition line_edit.hpp:96
@ INPUT
Routed input or programmatic activation.
Definition line_edit.hpp:97
std::expected< PasswordBinding, PasswordFailure > bindPassword(WidgetTree &tree, EventRouter &router, Node< Password > node, std::shared_ptr< Property< PasswordValue > > model, std::function< void(PasswordResult)> onResult, std::shared_ptr< Clipboard > clipboard={}, std::function< bool(SecretView)> validate={})
Bind and securely inspect the initial model before publishing presentation.
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
EditMode
When an accepted editing candidate is validated and published to its model.
Definition line_edit.hpp:27
@ IMMEDIATE
Publish each semantic-valid text change; invalid intermediate text remains visible.
Definition line_edit.hpp:28
An owning available extent in terminal columns/rows.
Definition geometry.hpp:44
Small owning paint value, independent of themes and text metrics.
Definition cell_buffer.hpp:35
Owning resolved presentation; no actions or model state are encoded.
Definition style_types.hpp:169
Owning paint values; no theme engine or behavior is encoded here.
Definition controls.hpp:24
Owning protected-editor policy; no plaintext history, copying or cutting exists.
Definition password.hpp:22
ControlStyle style
Normal, focused and disabled appearance.
Definition password.hpp:25
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
CellStyle selection
Selected mask appearance.
Definition password.hpp:26
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
CellStyle cursor
Software caret appearance.
Definition password.hpp:27
Secret-free editing outcome; a commit owns only protected immutable snapshots.
Definition password.hpp:60
std::optional< PropertyUpdate< PasswordValue > > commit
Exact successful receipt, including partial delivery.
Definition password.hpp:62
std::optional< TreeError > callbackError
Result-delivery exception, independent of publication/primary failure.
Definition password.hpp:65
PasswordStatus status
Editing/publication outcome.
Definition password.hpp:61
LineEditTrigger trigger
Routed input, fluent operation or synchronous blur.
Definition password.hpp:64
std::optional< PasswordFailure > failure
Original typed technical/Unicode failure without secret messages.
Definition password.hpp:63
Independent ownership and protected-access failures, without secret diagnostics.
Definition password_value.hpp:14
A primary failure and independently preserved bounded cleanup diagnostics.
Definition secure_string.hpp:182
Requested mandatory guarantees, established even for an empty value.
Definition secure_string.hpp:38
Owning independent policies for width and height.
Definition layout.hpp:35
Owning error value, independent of the failed input's lifetime.
Definition text.hpp:87
Owning limits checked without silently truncating input or clusters.
Definition text.hpp:57
Owning deterministic width policy; no font or terminal matching promise.
Definition text.hpp:42