Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
ui_form_field.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/form_field.hpp>
6#include <portals/ui_controls.hpp>
7#include <portals/ui_layout.hpp>
8
9#include <stop_token>
10
11namespace portals::ui {
12
15 std::size_t maxCandidateBytes{16 * 1024};
16 std::size_t maxMessageBytes{4 * 1024};
17};
18
23using AsyncFieldValidator = std::function<std::expected<FieldValidation, TreeError>(std::string_view, std::stop_token)>;
24
28 ~FormFieldConfig() = default;
29
30 std::string help;
31 bool required{};
32 std::function<FieldValidation(std::string_view)>
34 std::string requiredMessage{"A value is required"};
37 AsyncFieldValidator validateAsync{};
40 std::function<Description<Label>(ControlStyle)> captionRecipe;
42};
43
44namespace detail {
49Description<FormField> customFormField(std::string caption, Description<Widget> editor, FormFieldOptions options);
50
52std::expected<FieldValidation, ManagedError> fieldValidation(const std::shared_ptr<RefTarget> &target);
53
56Ref<LineEdit> fieldEditor(const std::shared_ptr<RefTarget> &target);
57
59std::expected<bool, ManagedError> validateField(const std::shared_ptr<RefTarget> &target);
60
64std::expected<void, ManagedError> displayField(const std::shared_ptr<RefTarget> &target, FieldValidation value);
65} // namespace detail
66
77Description<FormField> formField(std::string_view caption, std::string_view initial = {}, FormFieldConfig config = {});
78
83inline Description<FormField> formField(Ref<FormField> reference, std::string_view caption,
84 std::string_view initial = {}, FormFieldConfig config = {}) {
85 return formField(caption, initial, std::move(config)).reference(std::move(reference));
86}
87
94template <class T>
95Description<FormField> formField(std::string_view caption, Description<T> editor, FormFieldOptions options = {}) {
96 return detail::customFormField(std::string(caption), detail::Access::erase(std::move(editor)), std::move(options));
97}
98
99} // namespace portals::ui
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
Owning paint values; no theme engine or behavior is encoded here.
Definition controls.hpp:24
Owning validation presentation; messages remain meaningful without color.
Definition form_field.hpp:25
Manual style/layout defaults; semantic field rules are configured separately.
Definition form_field.hpp:46
Owning composition settings for an explicitly supplied custom editor.
Definition form_field.hpp:55
Byte budgets for an asynchronous field request and its final message; no silent truncation.
Definition ui_form_field.hpp:14
std::size_t maxCandidateBytes
Positive UTF-8 request byte limit; editor limits remain independent.
Definition ui_form_field.hpp:15
std::size_t maxMessageBytes
Positive complete result-message byte limit.
Definition ui_form_field.hpp:16
Standard text editor configuration; validation observes the normal publication boundaries.
Definition ui_form_field.hpp:26
AsyncFieldValidator validateAsync
Optional worker rule after synchronous checks; never called during paint.
Definition ui_form_field.hpp:37
FormFieldAppearance appearance
Manual composition style/layout defaults; contains no validation policy.
Definition ui_form_field.hpp:36
FieldValidationLimits validationLimits
Definition ui_form_field.hpp:38
LineEditConfig editor
Optional ordinary editor configuration, including EditMode/history/display policy.
Definition ui_form_field.hpp:35
std::function< FieldValidation(std::string_view)> validate
Synchronous owning rule; borrowed candidate expires on return.
Definition ui_form_field.hpp:33
~FormFieldConfig()=default
Preserve fallible owning argument transfers before mount.
std::string requiredMessage
Explanation of an empty required candidate.
Definition ui_form_field.hpp:34
bool required
Show a required marker and reject an empty publication candidate.
Definition ui_form_field.hpp:31
std::string help
Explanation below the editor; empty omits its row.
Definition ui_form_field.hpp:30
Owning optional editor customization and confirmation policy.
Definition ui_description.hpp:34
static Description< Widget > erase(Description< T > description)
Erase only the observer type while preserving one mount transaction.
Definition ui_description.hpp:3534