Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
form_field.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/controls.hpp>
6
7#include <functional>
8#include <string>
9
10namespace portals {
11namespace ui::detail {
12struct Access;
13}
14
23
27 ~FieldValidation() = default;
28
30 std::string message;
31
33 static FieldValidation valid(std::string message = {});
34
36 static FieldValidation invalid(std::string message = {});
37
39 static FieldValidation pending(std::string message = {});
40
42 static FieldValidation error(std::string message = {});
43};
44
53
57 ~FormFieldOptions() = default;
58
59 std::string help;
60 bool required{};
61 std::string requiredMessage{"A value is required"};
63};
64
65namespace detail {
66struct FormFieldRecord;
67}
68
73class FormField : public Column {
74public:
77
79 ~FormField() override;
80
83
86
87private:
88 friend struct ui::detail::Access;
89 friend std::expected<void, TreeError> setFormFieldValidation(WidgetTree &, Node<FormField>, FieldValidation);
90 std::shared_ptr<detail::FormFieldRecord> record_;
91};
92
99std::expected<void, TreeError> setFormFieldValidation(WidgetTree &tree, Node<FormField> node, FieldValidation value);
100
101} // namespace portals
Column(LinearOptions options={}, SizePolicy policy={})
Own settings and policies.
~FormField() override
Retire any borrowed validation bridge before child ownership is reclaimed.
Node< Widget > editor() const
FieldValidation validation() const
friend std::expected< void, TreeError > setFormFieldValidation(WidgetTree &, Node< FormField >, FieldValidation)
FormField(FormFieldAppearance options={})
LinearOptions options() const
Owning copy; no invalidation.
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
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
@ PENDING
Complete or abandon the owning session before submitting another frame.
Definition diff.hpp:108
FieldStatus
Presentation of the most recent explicit or editor-publication validation.
Definition form_field.hpp:16
@ VALID
The checked candidate satisfied all configured synchronous rules.
Definition form_field.hpp:18
@ UNCHECKED
No validation has been requested; required is still shown in the label.
Definition form_field.hpp:17
@ INVALID
The checked candidate was rejected; the editor retains its draft.
Definition form_field.hpp:19
@ TECHNICAL_ERROR
A technical validation failure; distinct from invalid business data.
Definition form_field.hpp:21
@ UNCHECKED
No selection.
Definition controls.hpp:267
std::expected< void, TreeError > setFormFieldValidation(WidgetTree &tree, Node< FormField > node, FieldValidation value)
constexpr SizePolicy DEFAULT_FLEX_WIDTH_POLICY
Fill available width from a zero flex basis while retaining content height.
Definition layout.hpp:47
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
static FieldValidation error(std::string message={})
static FieldValidation invalid(std::string message={})
static FieldValidation pending(std::string message={})
std::string message
Optional owning UTF-8 explanation.
Definition form_field.hpp:30
static FieldValidation valid(std::string message={})
FieldStatus status
Last requested presentation.
Definition form_field.hpp:29
~FieldValidation()=default
Keep owning transfers fallible on checked standard libraries.
Manual style/layout defaults; semantic field rules are configured separately.
Definition form_field.hpp:46
LinearOptions layout
Existing vertical layout settings.
Definition form_field.hpp:50
ControlStyle helpStyle
Manual help defaults beneath theme rules.
Definition form_field.hpp:48
SizePolicy policy
Existing container size constraints.
Definition form_field.hpp:51
ControlStyle messageStyle
Manual validation defaults beneath theme rules.
Definition form_field.hpp:49
ControlStyle labelStyle
Manual label defaults beneath theme rules.
Definition form_field.hpp:47
Owning composition settings for an explicitly supplied custom editor.
Definition form_field.hpp:55
bool required
Append the visible required marker; custom editors retain their own value rules.
Definition form_field.hpp:60
~FormFieldOptions()=default
Preserve fallible owning string transfers at the checked mount boundary.
FormFieldAppearance appearance
Manual style and layout defaults.
Definition form_field.hpp:62
std::string requiredMessage
Required rejection explanation for standard text fields.
Definition form_field.hpp:61
std::string help
Optional UTF-8 explanation below the editor.
Definition form_field.hpp:59
Owning linear container options.
Definition layout.hpp:193
Owning independent policies for width and height.
Definition layout.hpp:35
Internal bridge for checked access to managed scene and recipe state.
Definition ui_recipe_access.hpp:28