6#include <portals/form_field.hpp>
7#include <portals/managed_navigation.hpp>
8#include <portals/model_edit.hpp>
10namespace portals::detail {
12struct ManagedModelSource;
16 explicit EditTextDraft(GraphemeText value,
const LineEditOptions &options)
17 :
text(std::move(value)),
18 history(std::make_unique<TextHistory>(options.history, options.widthPolicy, options.limits)),
19 limits(options.limits) {
23 std::unique_ptr<GraphemeText> mask;
24 std::unique_ptr<TextHistory> history;
28 std::int32_t scroll{};
29 std::uint64_t revision{};
30 std::uint64_t generation{};
36struct EditStorageAccess {
37 static std::expected<std::size_t, TreeError> draftBytes(
const GraphemeText &text,
const GraphemeText *mask,
38 std::size_t history)
noexcept {
39 auto total =
sizeof(EditTextDraft) +
sizeof(TextHistory);
40 auto add = [&](std::size_t bytes) {
41 if (bytes > std::numeric_limits<std::size_t>::max() - total) {
47 auto payload = [&](
const GraphemeText &value) {
48 return value.graphemes_.capacity() <= std::numeric_limits<std::size_t>::max() /
sizeof(Grapheme) &&
49 add(value.bytes_.capacity()) && add(1) && add(value.graphemes_.capacity() *
sizeof(Grapheme));
51 if (!payload(text) || (mask && (!add(
sizeof(GraphemeText)) || !payload(*mask))) || !add(history)) {
52 return std::unexpected(TreeError::NODE_LIMIT);
59struct EditTextFailure {
64struct EditTextBinding {
65 Node<LineEdit> receiver;
66 EditTextDraft *displayed{};
67 EditTextDraft *prepared{};
68 void *displayedEntry{};
69 void *preparedEntry{};
71 bool validatedByEditor{};
73 const void *definition{};
76 bool retentionRefused{};
78 std::function<std::expected<std::shared_ptr<const FieldValidation>,
TreeError>()> validation;
79 std::function<std::expected<void, TreeError>(std::shared_ptr<const FieldValidation>)> displayValidation;
80 std::function<std::expected<void, TreeError>()> preserveValidation;
81 std::function<std::expected<bool, TreeError>(std::string_view)> checkCandidate;
82 std::function<std::expected<bool, TreeError>(std::string_view)> validateBeforeParse;
83 std::function<std::expected<bool, TreeError>(std::string_view)> validateForCommit;
84 std::function<std::expected<void, TreeError>(
const LineEditOptions &)>
initialize;
85 std::function<std::expected<void, TreeError>()> prepare;
86 std::function<std::expected<void, TreeError>(
const NavigationPosition &,
const std::shared_ptr<ManagedModelSource> &)>
88 std::function<std::expected<std::shared_ptr<const PropertyChange<std::string>>,
TreeError>()> snapshot;
89 std::function<std::expected<std::shared_ptr<const PropertyChange<std::string>>,
TreeError>()> cancelSnapshot;
90 std::function<std::expected<std::optional<PropertyUpdate<std::string>>,
TreeError>(
const std::string &)> publish;
91 std::function<std::expected<void, TreeError>(std::size_t,
bool)> admit;
92 std::function<void()> accepted;
93 std::function<std::expected<Subscription, TreeError>(Node<LineEdit>, std::function<
void()>)> observe;
94 std::function<std::expected<LineEditResult, TreeError>(
bool)> complete;
95 std::function<std::expected<LineEditResult, TreeError>(
const std::string &)> setText;
98struct EditNavigationParticipant {
99 virtual ~EditNavigationParticipant() =
default;
100 virtual std::expected<void, TreeError> beforeTransition(
const NavigationPosition *,
101 const std::shared_ptr<ManagedModelSource> &) = 0;
102 virtual void closed() noexcept = 0;
std::expected< void, ProcessContextError > initialize(int argc, const char *const *argv)
Capture argv and the environment once, before any concurrent foreign environment mutation....
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
LineEditStatus
Observable editing or service outcome; rejection preserves the draft.
Definition line_edit.hpp:81
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26