guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
text_field_configuration.cpp
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#include "guillaume/components/text_field_configuration.hpp"
24
25#include <algorithm>
26#include <utility>
27
29{
32 {
33 return _variant;
34 }
35
37 {
38 if (_variant == variant) {
39 return *this;
40 }
41 _variant = variant;
42 setHasChanged(true);
43 return *this;
44 }
45
46 const std::string &
48 {
49 return _leadingIcon;
50 }
51
54 {
55 if (_leadingIcon == glyph) {
56 return *this;
57 }
58 _leadingIcon = glyph;
59 setHasChanged(true);
60 return *this;
61 }
62
63 const std::string &
65 {
66 return _trailingIcon;
67 }
68
71 {
72 if (_trailingIcon == glyph) {
73 return *this;
74 }
75 _trailingIcon = glyph;
76 setHasChanged(true);
77 return *this;
78 }
79
80 const std::string &TextFieldConfiguration::getText(void) const noexcept
81 {
82 return _text;
83 }
84
86 TextFieldConfiguration::setText(const std::string &text)
87 {
88 if (_text == text) {
89 return *this;
90 }
91 _text = text;
92 setHasChanged(true);
93 return *this;
94 }
95
96 bool TextFieldConfiguration::isEditable(void) const noexcept
97 {
98 return _editable;
99 }
100
102 {
103 if (_editable == editable) {
104 return *this;
105 }
106 _editable = editable;
107 setHasChanged(true);
108 return *this;
109 }
110
111 bool TextFieldConfiguration::isDense(void) const noexcept
112 {
113 return _dense;
114 }
115
117 {
118 if (_dense == dense) {
119 return *this;
120 }
121 _dense = dense;
122 setHasChanged(true);
123 return *this;
124 }
125
126 bool TextFieldConfiguration::isMultiline(void) const noexcept
127 {
128 return _multiline;
129 }
130
132 {
133 if (_multiline == multiline) {
134 return *this;
135 }
136 _multiline = multiline;
137 setHasChanged(true);
138 return *this;
139 }
140
141 const std::optional<float> &
143 {
144 return _width;
145 }
146
148 TextFieldConfiguration::setWidth(std::optional<float> width)
149 {
150 if (width.has_value()) {
151 width = std::max(MinWidth, *width);
152 }
153 if (_width == width) {
154 return *this;
155 }
156 _width = width;
157 setHasChanged(true);
158 return *this;
159 }
160
163 {
164 return _onChange;
165 }
166
169 {
170 _onChange = std::move(handler);
171 return *this;
172 }
173
176 {
177 return _onFocus;
178 }
179
181 {
182 _onFocus = std::move(handler);
183 return *this;
184 }
185
188 {
189 return _onBlur;
190 }
191
193 {
194 _onBlur = std::move(handler);
195 return *this;
196 }
197
200 {
201 return _leadingIconEntity;
202 }
203
205 ecs::Entity::Identifier identifier)
206 {
207 if (_leadingIconEntity == identifier) {
208 return *this;
209 }
210 _leadingIconEntity = identifier;
211 setHasChanged(true);
212 return *this;
213 }
214
217 {
218 return _trailingIconEntity;
219 }
220
222 ecs::Entity::Identifier identifier)
223 {
224 if (_trailingIconEntity == identifier) {
225 return *this;
226 }
227 _trailingIconEntity = identifier;
228 setHasChanged(true);
229 return *this;
230 }
231
234 {
235 return _errorIconEntity;
236 }
237
239 ecs::Entity::Identifier identifier)
240 {
241 if (_errorIconEntity == identifier) {
242 return *this;
243 }
244 _errorIconEntity = identifier;
245 setHasChanged(true);
246 return *this;
247 }
248
251 {
252 return _inputColumn;
253 }
254
256 ecs::Entity::Identifier identifier)
257 {
258 if (_inputColumn == identifier) {
259 return *this;
260 }
261 _inputColumn = identifier;
262 setHasChanged(true);
263 return *this;
264 }
265
268 {
269 return _labelEntity;
270 }
271
273 ecs::Entity::Identifier identifier)
274 {
275 if (_labelEntity == identifier) {
276 return *this;
277 }
278 _labelEntity = identifier;
279 setHasChanged(true);
280 return *this;
281 }
282
285 {
286 return _inputEntity;
287 }
288
290 ecs::Entity::Identifier identifier)
291 {
292 if (_inputEntity == identifier) {
293 return *this;
294 }
295 _inputEntity = identifier;
296 setHasChanged(true);
297 return *this;
298 }
299
302 {
303 return _prefixEntity;
304 }
305
307 ecs::Entity::Identifier identifier)
308 {
309 if (_prefixEntity == identifier) {
310 return *this;
311 }
312 _prefixEntity = identifier;
313 setHasChanged(true);
314 return *this;
315 }
316
319 {
320 return _suffixEntity;
321 }
322
324 ecs::Entity::Identifier identifier)
325 {
326 if (_suffixEntity == identifier) {
327 return *this;
328 }
329 _suffixEntity = identifier;
330 setHasChanged(true);
331 return *this;
332 }
333
336 {
337 return _supportingEntity;
338 }
339
341 ecs::Entity::Identifier identifier)
342 {
343 if (_supportingEntity == identifier) {
344 return *this;
345 }
346 _supportingEntity = identifier;
347 setHasChanged(true);
348 return *this;
349 }
350} // namespace guillaume::components
State of a text field widget that is not text around the input: its variant, icons,...
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.
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.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
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
State. Every class here is plain data attached to an entity.