guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
text_field_configuration.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <functional>
26#include <optional>
27#include <string>
28
29#include "guillaume/ecs/component.hpp"
30#include "guillaume/ecs/entity.hpp"
31
33{
34
55 {
56 public:
61 enum class Variant { Filled, Outlined };
62
65 using ChangeHandler = std::function<void(const std::string &)>;
66
69 using Handler = std::function<void(void)>;
70
72 static constexpr float MinWidth = 100.0f;
73
74 private:
75 Variant _variant { Variant::Filled };
76 std::string _leadingIcon {};
77 std::string _trailingIcon {};
78 std::string _text {};
79 bool _editable { true };
80 bool _dense { false };
81 bool _multiline { false };
82 std::optional<float> _width {};
83 ChangeHandler _onChange {};
84 Handler _onFocus {};
85 Handler _onBlur {};
86 ecs::Entity::Identifier _leadingIconEntity {
88 };
89
90 ecs::Entity::Identifier _trailingIconEntity {
92 };
93
94 ecs::Entity::Identifier _errorIconEntity {
96 };
97
98 ecs::Entity::Identifier _inputColumn {
100 };
101
102 ecs::Entity::Identifier _labelEntity {
104 };
105
106 ecs::Entity::Identifier _inputEntity {
108 };
109
110 ecs::Entity::Identifier _prefixEntity {
112 };
113
114 ecs::Entity::Identifier _suffixEntity {
116 };
117
118 ecs::Entity::Identifier _supportingEntity {
120 };
121
122 public:
127 TextFieldConfiguration(void) = default;
128
132 ~TextFieldConfiguration(void) = default;
133
138 Variant getVariant(void) const noexcept;
139
148
153 const std::string &getLeadingIcon(void) const noexcept;
154
163 TextFieldConfiguration &setLeadingIcon(const std::string &glyph);
164
169 const std::string &getTrailingIcon(void) const noexcept;
170
180 TextFieldConfiguration &setTrailingIcon(const std::string &glyph);
181
190 const std::string &getText(void) const noexcept;
191
201 TextFieldConfiguration &setText(const std::string &text);
202
207 bool isEditable(void) const noexcept;
208
218 TextFieldConfiguration &setEditable(bool editable);
219
224 bool isDense(void) const noexcept;
225
235 TextFieldConfiguration &setDense(bool dense);
236
241 bool isMultiline(void) const noexcept;
242
251 TextFieldConfiguration &setMultiline(bool multiline);
252
258 const std::optional<float> &getWidth(void) const noexcept;
259
269 TextFieldConfiguration &setWidth(std::optional<float> width);
270
275 const ChangeHandler &getOnChange(void) const noexcept;
276
288
293 const Handler &getOnFocus(void) const noexcept;
294
303
308 const Handler &getOnBlur(void) const noexcept;
309
318
325
335
342
352
359 ecs::Entity::Identifier getErrorIconEntity(void) const noexcept;
360
371
377 ecs::Entity::Identifier getInputColumn(void) const noexcept;
378
388
395 ecs::Entity::Identifier getLabelEntity(void) const noexcept;
396
406
412 ecs::Entity::Identifier getInputEntity(void) const noexcept;
413
424
430 ecs::Entity::Identifier getPrefixEntity(void) const noexcept;
431
441
447 ecs::Entity::Identifier getSuffixEntity(void) const noexcept;
448
458
465 ecs::Entity::Identifier getSupportingEntity(void) const noexcept;
466
477 };
478
479} // namespace guillaume::components
ecs::Entity::Identifier getLabelEntity(void) const noexcept
Get the child that draws the label (the placeholder text).
ecs::Entity::Identifier getInputColumn(void) const noexcept
Get the column that stacks the label above the input.
bool isMultiline(void) const noexcept
Tell whether the field grows with its content.
TextFieldConfiguration(void)=default
Create the configuration of an editable, single-line filled field with no icon and no forced width.
TextFieldConfiguration & setTrailingIconEntity(ecs::Entity::Identifier identifier)
Record the child that draws the trailing icon.
ecs::Entity::Identifier getSupportingEntity(void) const noexcept
Get the child that draws the supporting or error text under the field.
TextFieldConfiguration & setTrailingIcon(const std::string &glyph)
Set the icon shown after the input.
ecs::Entity::Identifier getInputEntity(void) const noexcept
Get the child the user types in.
TextFieldConfiguration & setVariant(Variant variant)
Choose between the filled and the outlined look.
TextFieldConfiguration & setErrorIconEntity(ecs::Entity::Identifier identifier)
Record the child that draws the icon shown while the field is in error.
TextFieldConfiguration & setSupportingEntity(ecs::Entity::Identifier identifier)
Record the child that draws the supporting or error text under the field.
bool isEditable(void) const noexcept
Tell whether the user can edit the text.
const std::string & getLeadingIcon(void) const noexcept
Get the icon shown before the input.
TextFieldConfiguration & setPrefixEntity(ecs::Entity::Identifier identifier)
Record the child that draws the prefix.
TextFieldConfiguration & setDense(bool dense)
Choose between the regular and the compact height.
static constexpr float MinWidth
Smallest width of a text field, in dp.
const ChangeHandler & getOnChange(void) const noexcept
Get the callback run when the user edits the text.
const std::string & getText(void) const noexcept
Get the last known input text.
ecs::Entity::Identifier getErrorIconEntity(void) const noexcept
Get the child that draws the icon shown while the field is in error.
TextFieldConfiguration & setInputColumn(ecs::Entity::Identifier identifier)
Record the column that stacks the label above the input.
TextFieldConfiguration & setLeadingIcon(const std::string &glyph)
Set the icon shown before the input.
TextFieldConfiguration & setMultiline(bool multiline)
Choose between a fixed height and a height that follows the content.
Variant getVariant(void) const noexcept
Get the look of the field.
TextFieldConfiguration & setOnChange(ChangeHandler handler)
Set the callback run when the user edits the text.
TextFieldConfiguration & setLeadingIconEntity(ecs::Entity::Identifier identifier)
Record the child that draws the leading icon.
TextFieldConfiguration & setText(const std::string &text)
Store the last known input text.
const Handler & getOnFocus(void) const noexcept
Get the callback run when the field gains the focus.
TextFieldConfiguration & setInputEntity(ecs::Entity::Identifier identifier)
Record the child the user types in.
TextFieldConfiguration & setOnBlur(Handler handler)
Set the callback run when the field loses the focus.
TextFieldConfiguration & setOnFocus(Handler handler)
Set the callback run when the field gains the focus.
std::function< void(const std::string &)> ChangeHandler
ecs::Entity::Identifier getSuffixEntity(void) const noexcept
Get the child that draws the suffix.
const Handler & getOnBlur(void) const noexcept
Get the callback run when the field loses the focus.
const std::optional< float > & getWidth(void) const noexcept
Get the forced width of the field.
bool isDense(void) const noexcept
Tell whether the field uses the compact height.
const std::string & getTrailingIcon(void) const noexcept
Get the icon shown after the input.
ecs::Entity::Identifier getPrefixEntity(void) const noexcept
Get the child that draws the prefix.
TextFieldConfiguration & setWidth(std::optional< float > width)
Force the width of the field, or let it follow its content.
TextFieldConfiguration & setEditable(bool editable)
Allow or forbid editing by the user.
Variant
Look of the field: Filled has a tinted background and a line under it; Outlined has a border the labe...
TextFieldConfiguration & setSuffixEntity(ecs::Entity::Identifier identifier)
Record the child that draws the suffix.
~TextFieldConfiguration(void)=default
Default destructor.
ecs::Entity::Identifier getTrailingIconEntity(void) const noexcept
Get the child that draws the trailing icon.
ecs::Entity::Identifier getLeadingIconEntity(void) const noexcept
Get the child that draws the leading icon.
TextFieldConfiguration & setLabelEntity(ecs::Entity::Identifier identifier)
Record the child that draws the label.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
State. Every class here is plain data attached to an entity.