guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
text_field.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/systems/text_field.hpp"
24
25#include <algorithm>
26#include <cstdint>
27#include <vector>
28
29#include "guillaume/components/accessibility.hpp"
30#include "guillaume/components/borders.hpp"
31#include "guillaume/components/bound.hpp"
32#include "guillaume/components/color.hpp"
33#include "guillaume/components/focus.hpp"
34#include "guillaume/components/layout.hpp"
35#include "guillaume/components/line.hpp"
36#include "guillaume/components/style_state.hpp"
37#include "guillaume/components/transform.hpp"
38#include "guillaume/components/typography.hpp"
42#include "guillaume/systems/layout.hpp"
43#include "guillaume/systems/typography.hpp"
44#include "guillaume/theme.hpp"
45
46namespace guillaume::systems
47{
48 namespace
49 {
50 using Configuration = components::TextFieldConfiguration;
51 using Variant = Configuration::Variant;
56
58 constexpr std::uint8_t DisabledFilledAlpha = 10U;
59
67 utility::graphic::Color32Bit activeColor(bool disabled, bool error,
68 bool focused)
69 {
70 if (disabled) {
71 return disabledContentColor();
72 }
73 if (error) {
74 return schemeColor(SchemeColorRole::Error);
75 }
76 if (focused) {
77 return schemeColor(SchemeColorRole::Primary);
78 }
79 return schemeColor(SchemeColorRole::OnSurfaceVariant);
80 }
81
88 void colorChild(ecs::ComponentRegistry &registry,
90 const utility::graphic::Color32Bit &color)
91 {
92 if (registry.hasComponent<components::Color>(child)) {
93 registry.getComponent<components::Color>(child).setColor(color);
94 }
95 }
96
103 void writeChild(ecs::ComponentRegistry &registry,
105 const std::string &content)
106 {
107 if (registry.hasComponent<components::Text>(child)) {
108 registry.getComponent<components::Text>(child).setContent(
109 content);
110 }
111 }
112
118 void arrange(ecs::ComponentRegistry &registry,
119 ecs::Entity::Identifier container)
120 {
121 if (!registry.hasComponent<components::Layout>(container)
122 || !registry.hasComponent<components::Transform>(container)
123 || !registry.hasComponent<components::Bound>(container)) {
124 return;
125 }
126 Layout::apply(registry, container,
127 registry.getComponent<components::Layout>(container)
128 .getChildren(),
129 Layout::layerOf(registry, container));
130 }
131
138 void reportChange(ecs::ComponentRegistry &registry,
139 ecs::Entity::Identifier identifier)
140 {
141 auto &configuration =
142 registry.getComponent<Configuration>(identifier);
143 const std::string current = TextField::text(registry, identifier);
144
145 if (current == configuration.getText()) {
146 return;
147 }
148 configuration.setText(current);
149
150 // Copy: the callback may replace itself.
151 const auto onChange = configuration.getOnChange();
152 if (onChange) {
153 onChange(current);
154 }
155 }
156
163 void styleChildren(ecs::ComponentRegistry &registry,
164 ecs::Entity::Identifier identifier)
165 {
166 const auto &configuration =
167 registry.getComponent<Configuration>(identifier);
168 const auto &field =
169 registry.getComponent<components::TextField>(identifier);
170 const bool disabled = TextField::isDisabled(registry, identifier);
171 const bool floating =
172 TextField::isLabelFloating(registry, identifier);
173 const bool error = field.isError();
174 const auto content = disabled
176 : schemeColor(SchemeColorRole::OnSurface);
177 const auto variantColor = disabled
179 : schemeColor(SchemeColorRole::OnSurfaceVariant);
180 const auto errorColor = (error && !disabled)
181 ? schemeColor(SchemeColorRole::Error)
183 const auto label = configuration.getLabelEntity();
184
185 writeChild(registry, label, field.getPlaceholder());
186 writeChild(registry, configuration.getPrefixEntity(),
187 field.getPrefix());
188 writeChild(registry, configuration.getSuffixEntity(),
189 field.getSuffix());
190 writeChild(registry, configuration.getSupportingEntity(),
191 TextField::supportingText(registry, identifier));
192
193 // The label rests at the input size and floats at the small one.
194 if (registry.hasComponent<components::Typography>(label)
195 && registry.hasComponent<components::Text>(label)) {
196 registry.getComponent<components::Typography>(label)
197 .setRole(floating ? theme::TypeRole::BodySmall
199 .setFontSize(std::nullopt);
200 Typography::apply(registry, label);
201 }
202
203 colorChild(registry, configuration.getInputEntity(), content);
204 colorChild(registry, label,
205 floating ? activeColor(disabled, error,
206 TextField::isFocused(registry,
207 identifier))
208 : variantColor);
209 colorChild(registry, configuration.getLeadingIconEntity(),
210 variantColor);
211 colorChild(registry, configuration.getTrailingIconEntity(),
212 error ? transparentColor() : variantColor);
213 colorChild(registry, configuration.getErrorIconEntity(),
214 errorColor);
215 colorChild(registry, configuration.getPrefixEntity(),
216 floating ? variantColor : transparentColor());
217 colorChild(registry, configuration.getSuffixEntity(),
218 floating ? variantColor : transparentColor());
219 colorChild(registry, configuration.getSupportingEntity(),
220 (error && !disabled) ? errorColor : variantColor);
221 }
222
229 void arrangeChildren(ecs::ComponentRegistry &registry,
230 ecs::Entity::Identifier identifier)
231 {
232 const auto invalid = ecs::Entity::InvalidIdentifier;
233 const auto &configuration =
234 registry.getComponent<Configuration>(identifier);
235 const auto &field =
236 registry.getComponent<components::TextField>(identifier);
237 const bool floating =
238 TextField::isLabelFloating(registry, identifier);
239 const auto column = configuration.getInputColumn();
240 const auto label = configuration.getLabelEntity();
241 const auto input = configuration.getInputEntity();
242
243 // Input column: the filled label floats above the input, the
244 // outlined label floats on the outline (placed manually).
245 if (registry.hasComponent<components::Layout>(column)) {
246 std::vector<ecs::Entity::Identifier> columnChildren;
247 if (label != invalid
248 && (!floating
249 || configuration.getVariant() == Variant::Filled)) {
250 columnChildren.push_back(label);
251 }
252 if (input != invalid && (floating || label == invalid)) {
253 columnChildren.push_back(input);
254 }
255 registry.getComponent<components::Layout>(column).setChildren(
256 columnChildren);
257 // Resolves the column bound the row is sized from.
258 arrange(registry, column);
259 }
260
261 std::vector<ecs::Entity::Identifier> children;
262 if (configuration.getLeadingIconEntity() != invalid) {
263 children.push_back(configuration.getLeadingIconEntity());
264 }
265 if (configuration.getPrefixEntity() != invalid && floating) {
266 children.push_back(configuration.getPrefixEntity());
267 }
268 if (column != invalid) {
269 children.push_back(column);
270 }
271 if (configuration.getSuffixEntity() != invalid && floating) {
272 children.push_back(configuration.getSuffixEntity());
273 }
274 if (field.isError()) {
275 if (configuration.getErrorIconEntity() != invalid) {
276 children.push_back(configuration.getErrorIconEntity());
277 }
278 } else if (configuration.getTrailingIconEntity() != invalid) {
279 children.push_back(configuration.getTrailingIconEntity());
280 }
281
282 // Intrinsic width: content plus padding, never below MinWidth.
283 float width = 2.0f * TextField::Padding;
284 for (const auto child: children) {
285 if (registry.hasComponent<components::Bound>(child)) {
286 width += registry.getComponent<components::Bound>(child)
287 .getWidth();
288 }
289 }
290 if (children.size() > 1) {
291 width += TextField::Spacing
292 * static_cast<float>(children.size() - 1);
293 }
294
295 auto &layout =
296 registry.getComponent<components::Layout>(identifier);
297 layout
298 .setFixedWidth(
299 std::max(Configuration::MinWidth,
300 configuration.getWidth().value_or(width)))
301 .setChildren(children);
302 arrange(registry, identifier);
303 // The row has just moved the column: carry its children along.
304 arrange(registry, column);
305 }
306
313 void placeManualChildren(ecs::ComponentRegistry &registry,
314 ecs::Entity::Identifier identifier)
315 {
316 const auto invalid = ecs::Entity::InvalidIdentifier;
317 const auto &configuration =
318 registry.getComponent<Configuration>(identifier);
319 const auto layer = Layout::layerOf(registry, identifier);
320 const float height =
321 registry.getComponent<components::Bound>(identifier)
322 .getHeight();
323 const auto supporting = configuration.getSupportingEntity();
324 const auto label = configuration.getLabelEntity();
325
326 if (supporting != invalid) {
327 placement::placeChild(registry, identifier, supporting,
328 utility::graphic::PositionF(
331 0.0f),
332 layer);
333 }
334
335 if (label != invalid
336 && configuration.getVariant() == Variant::Outlined
337 && TextField::isLabelFloating(registry, identifier)) {
338 float x = TextField::Padding;
339 if (configuration.getLeadingIconEntity() != invalid) {
341 }
342 const float lineHeight =
345 registry, identifier, label,
346 utility::graphic::PositionF(x, -lineHeight / 2.0f, 0.0f),
347 layer);
348 }
349 }
350 } // namespace
351
356
358 const ecs::Entity::Identifier &entityIdentifier)
359 {
360 ecs::ComponentRegistry *registry = &componentRegistry;
361 const ecs::Entity::Identifier identifier = entityIdentifier;
362
363 interaction::makeInteractive(componentRegistry, identifier,
365 {}, [registry, identifier]() {
366 applyContainer(*registry, identifier);
367 });
368
369 auto &focus =
370 componentRegistry.getComponent<components::Focus>(identifier);
371 focus.setOnFocusGainedHandler([registry, identifier]() {
372 // Copy: the callback may replace itself.
373 const auto onFocus =
374 registry->getComponent<Configuration>(identifier).getOnFocus();
375 if (onFocus) {
376 onFocus();
377 }
378 });
379 focus.setOnFocusLostHandler([registry, identifier]() {
380 // Copy: the callback may replace itself.
381 const auto onBlur =
382 registry->getComponent<Configuration>(identifier).getOnBlur();
383 if (onBlur) {
384 onBlur();
385 }
386 });
387 }
388
389 bool TextField::isFocused(const ecs::ComponentRegistry &componentRegistry,
390 const ecs::Entity::Identifier &entityIdentifier)
391 {
392 if (componentRegistry.hasComponent<components::Focus>(entityIdentifier)
393 && componentRegistry
394 .getComponent<components::Focus>(entityIdentifier)
395 .isFocused()) {
396 return true;
397 }
398 return componentRegistry.hasComponent<components::StyleState>(
399 entityIdentifier)
400 && componentRegistry
401 .getComponent<components::StyleState>(entityIdentifier)
402 .isFocused();
403 }
404
405 bool TextField::isDisabled(const ecs::ComponentRegistry &componentRegistry,
406 const ecs::Entity::Identifier &entityIdentifier)
407 {
408 return !interaction::isEnabled(componentRegistry, entityIdentifier);
409 }
410
412 const ecs::ComponentRegistry &componentRegistry,
413 const ecs::Entity::Identifier &entityIdentifier)
414 {
415 return isFocused(componentRegistry, entityIdentifier)
416 || !text(componentRegistry, entityIdentifier).empty();
417 }
418
419 std::string TextField::text(const ecs::ComponentRegistry &componentRegistry,
420 const ecs::Entity::Identifier &entityIdentifier)
421 {
422 const auto &configuration =
423 componentRegistry.getComponent<Configuration>(entityIdentifier);
424 const auto input = configuration.getInputEntity();
425
426 if (!componentRegistry.hasComponent<components::Text>(input)) {
427 return configuration.getText();
428 }
429 return componentRegistry.getComponent<components::Text>(input)
430 .getContent();
431 }
432
434 const ecs::Entity::Identifier &entityIdentifier,
435 const std::string &text)
436 {
437 auto &configuration =
438 componentRegistry.getComponent<Configuration>(entityIdentifier);
439
440 // Recording the text first keeps the change callback silent.
441 configuration.setText(text);
442 writeChild(componentRegistry, configuration.getInputEntity(), text);
443 apply(componentRegistry, entityIdentifier);
444 }
445
447 const ecs::Entity::Identifier &entityIdentifier,
448 bool disabled)
449 {
450 interaction::setEnabled(componentRegistry, entityIdentifier, !disabled);
451 apply(componentRegistry, entityIdentifier);
452 }
453
455 const ecs::ComponentRegistry &componentRegistry,
456 const ecs::Entity::Identifier &entityIdentifier)
457 {
458 const auto &field =
459 componentRegistry.getComponent<components::TextField>(
460 entityIdentifier);
461
462 return (field.isError() && !field.getErrorText().empty())
463 ? field.getErrorText()
464 : field.getSupportingText();
465 }
466
468 ecs::ComponentRegistry &componentRegistry,
469 const ecs::Entity::Identifier &entityIdentifier)
470 {
471 const auto &configuration =
472 componentRegistry.getComponent<Configuration>(entityIdentifier);
473 const auto &field =
474 componentRegistry.getComponent<components::TextField>(
475 entityIdentifier);
476 auto &layout = componentRegistry.getComponent<components::Layout>(
477 entityIdentifier);
478 auto &color =
479 componentRegistry.getComponent<components::Color>(entityIdentifier);
480 auto &borders = componentRegistry.getComponent<components::Borders>(
481 entityIdentifier);
482 auto &line =
483 componentRegistry.getComponent<components::Line>(entityIdentifier);
484
485 const bool disabled = isDisabled(componentRegistry, entityIdentifier);
486 const bool focused =
487 isFocused(componentRegistry, entityIdentifier) && !disabled;
488 const bool error = field.isError();
489 const float stroke = focused ? 2.0f : 1.0f;
490
493 .setCrossAxisAlignment(
495 .setSpacing(Spacing)
496 .setPadding(Padding);
497 if (configuration.isMultiline()) {
498 layout.clearFixedHeight();
499 } else if (!configuration.isDense()) {
500 layout.setFixedHeight(Height);
501 } else {
502 layout.setFixedHeight(field.getPlaceholder().empty()
505 }
506
507 if (configuration.getVariant() == Variant::Outlined) {
508 auto outline = schemeColor(SchemeColorRole::Outline);
509 if (disabled) {
510 outline = disabledContainerColor();
511 } else if (error) {
512 outline = schemeColor(SchemeColorRole::Error);
513 } else if (focused) {
514 outline = schemeColor(SchemeColorRole::Primary);
515 }
516 color.setColor(transparentColor());
517 borders
519 .setColor(outline)
520 .setWidth(stroke);
521 line.setThickness(0.0f).clearColor();
522 } else {
523 color.setColor(
524 disabled
525 ? style::withAlpha(schemeColor(SchemeColorRole::OnSurface),
526 DisabledFilledAlpha)
527 : schemeColor(SchemeColorRole::SurfaceContainerHighest));
528 borders.setBorderRadius(getShapeRadius(theme::ShapeRole::None))
530 .setWidth(0.0f);
531 line.setThickness(stroke)
533 .setColor(activeColor(disabled, error, focused));
534 }
535 }
536
537 void
539 const ecs::Entity::Identifier &entityIdentifier)
540 {
541 const auto &configuration =
542 componentRegistry.getComponent<Configuration>(entityIdentifier);
543 const auto input = configuration.getInputEntity();
544
545 if (input == ecs::Entity::InvalidIdentifier) {
546 return;
547 }
548
549 const bool editing = configuration.isEditable()
550 && !isDisabled(componentRegistry, entityIdentifier)
551 && isFocused(componentRegistry, entityIdentifier);
552 const bool hasFocus =
553 componentRegistry.hasComponent<components::Focus>(input);
554
555 if (editing && !hasFocus) {
556 componentRegistry.addComponent<components::Focus>(input);
557 } else if (!editing && hasFocus) {
558 componentRegistry.removeComponent<components::Focus>(input);
559 }
560 }
561
563 const ecs::Entity::Identifier &entityIdentifier)
564 {
565 // May run user code: nothing is read before it returns.
566 reportChange(componentRegistry, entityIdentifier);
567
568 applyContainer(componentRegistry, entityIdentifier);
569
570 auto &field = componentRegistry.getComponent<components::TextField>(
571 entityIdentifier);
572 field.setLabel(field.getPlaceholder())
574 isLabelFloating(componentRegistry, entityIdentifier));
575 if (componentRegistry.hasComponent<components::Accessibility>(
576 entityIdentifier)) {
577 componentRegistry
578 .getComponent<components::Accessibility>(entityIdentifier)
579 .setLabel(field.getPlaceholder())
580 .setHint(field.getSupportingText());
581 }
582
583 styleChildren(componentRegistry, entityIdentifier);
584 arrangeChildren(componentRegistry, entityIdentifier);
585 placeManualChildren(componentRegistry, entityIdentifier);
586 applyEditing(componentRegistry, entityIdentifier);
587 }
588
589 void TextField::update(const ecs::Entity::Identifier &entityIdentifier)
590 {
591 if (!requireComponent<components::TextField>(entityIdentifier)) {
592 return;
593 }
594
595 auto &registry = getComponentRegistry();
596
597 if (registry.hasComponent<Configuration>(entityIdentifier)) {
598 apply(registry, entityIdentifier);
599 return;
600 }
601
602 // A bare field over its own Text only derives the floating state.
603 if (registry.hasComponent<components::Text>(entityIdentifier)) {
604 reconcile(
605 registry.getComponent<components::TextField>(entityIdentifier),
606 !registry.getComponent<components::Text>(entityIdentifier)
607 .getContent()
608 .empty());
609 }
610 }
611
612 bool TextField::reconcile(components::TextField &textField, bool hasContent)
613 {
614 const bool floating = hasContent || textField.isError();
615 textField.setLabelFloating(floating);
616 return floating;
617 }
618
619} // namespace guillaume::systems
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setHint(const std::string &hint)
Set the sentence describing what activating the entity does, such as "Closes the dialog".
Corner radii and outline stroke of a rectangular entity.
Definition borders.hpp:67
Borders & setColor(const utility::graphic::Color32Bit &color)
Set the color of the stroke.
Definition borders.cpp:107
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Definition color.hpp:58
Color & setColor(const utility::graphic::Color32Bit &color)
Set the color.
Definition color.cpp:37
Makes an entity able to own the input focus, and holds whether it owns it and what to call when it ga...
Definition focus.hpp:57
bool isFocused(void) const
Check whether the entity owns the input focus.
Definition focus.cpp:48
void setOnFocusGainedHandler(const Handler &handler)
Store the callback run when the entity gains the focus.
Definition focus.cpp:27
How a container arranges its children: in a row or a column, with which alignment,...
Definition layout.hpp:69
@ Start
Packed at the left (row) or top (column).
Definition layout.hpp:87
@ Horizontal
Row: children placed left to right.
Definition layout.hpp:75
A straight stroke across the width of the entity: a divider, an indicator, the underline of a text fi...
Definition line.hpp:62
The interaction state of an entity in one place: enabled or disabled, and whether it is hovered,...
The texts around the input of a text field, and its error state: placeholder, label,...
bool isError(void) const
Tell whether the field is in error.
const std::string & getErrorText(void) const
Get the message shown under the field while it is in error.
TextField & setLabel(const std::string &label)
Store the label.
TextField & setLabelFloating(bool floating)
Store whether the label floats above the input.
A run of text: its content, its font metrics and the position of the editing cursor.
Definition text.hpp:66
const std::string & getContent(void) const
Get the text.
Definition text.cpp:29
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
void removeComponent(const Entity::Identifier &entityIdentifier)
Delete one component of an entity. Does nothing when the entity does not have it.
ComponentType & addComponent(const Entity::Identifier &entityIdentifier, Args &&...args)
Construct a component for an entity, replacing the one it already has, if any.
bool hasComponent(const Entity::Identifier &entityIdentifier) const
Tell whether an entity has a component of a given type.
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
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
Definition system.cpp:53
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
Arranges the children of a container in a row or a column and sizes the container around them.
Definition layout.hpp:84
static void apply(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &parentIdentifier, const std::vector< ecs::Entity::Identifier > &childIdentifiers, std::uint32_t layer=0)
Arrange children inside a container and size the container.
Definition layout.cpp:126
static std::uint32_t layerOf(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Get the layer of an entity: its depth in the entity tree.
Definition layout.cpp:90
static constexpr float Height
Height of a single-line field that is not dense, in dp.
static bool isFocused(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the field has the input focus.
static constexpr float Padding
static constexpr float DenseHeight
Height of a dense single-line field without a label, in dp.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make an entity focusable and hoverable as a text field.
static std::string text(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the text the field holds.
static constexpr float DenseLabelHeight
Height of a dense single-line field that has a label, in dp.
static void setDisabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool disabled)
Enable or disable the field and restyle it.
static void applyEditing(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Let the input child receive typed text only while the field is being edited.
static constexpr float IconSize
static void applyContainer(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style the container only, leaving the children alone.
static bool isDisabled(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the field ignores input.
static void setText(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, const std::string &text)
Replace the text from code and restyle the field.
static constexpr float SupportingGap
static bool reconcile(components::TextField &textField, bool hasContent)
Derive the label-floating flag of a field that has no configuration, and store it.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Update one entity that has a components::TextField; called by the frame loop.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Report an edit, then style one text field and arrange its children.
TextField(void)
Create the system in the Layout phase.
static constexpr float Spacing
Gap between the icons, the affixes and the input: 12 dp.
static bool isLabelFloating(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the label is in its floating position.
static std::string supportingText(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the text shown below the field.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Resolve the metrics of one text and write them into its components::Text.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Definition component.hpp:28
void placeChild(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &parentIdentifier, const ecs::Entity::Identifier &childIdentifier, const utility::graphic::PositionF &offset, std::uint32_t parentLayer)
Place a child at an offset from the position of its parent.
utility::graphic::Color32Bit disabledContainerColor(void)
Fill color of the container of a disabled widget.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit disabledContentColor(void)
Color of the icon, label or outline of a disabled widget.
utility::graphic::Color32Bit withAlpha(const utility::graphic::Color32Bit &color, std::uint8_t alpha)
Copy a color with another alpha channel.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
Rules. Every class here runs each frame on the entities that have the components it declares.
utility::graphic::Color32Bit disabledContainerColor(void)
Fill color of the container of a disabled widget.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit disabledContentColor(void)
Color of the icon, label or outline of a disabled widget.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ BodyLarge
16 / 24, regular.
Definition typescale.hpp:60
@ BodySmall
12 / 16, regular.
Definition typescale.hpp:62
@ None
0 dp: square corners.
Definition tokens.hpp:43
@ ExtraSmall
4 dp (text fields, menus, snackbars).
Definition tokens.hpp:44
const theme::TypeToken & getTypeToken(theme::TypeRole role)
Get the text style the active theme gives to a role: font family, weight, size, line height and lette...
SchemeColorRole
The named colors of a scheme: what a color is used for, not what it looks like.
Definition theme.hpp:58
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
float lineHeight
Distance between two baselines, in dp.
Definition typescale.hpp:87
Helpers of the namespace systems::interaction: what "pressable" means for a widget,...
bool isEnabled(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &entityIdentifier)
Whether an entity accepts input.
void makeInteractive(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &entityIdentifier, components::AccessibilityRole role, std::function< void(void)> onPress, std::function< void(void)> onStateChange={})
Make an entity hoverable, pressable and focusable.
void setEnabled(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &entityIdentifier, bool enabled)
Enable or disable an entity.
Placement helpers for the children systems::Layout does not arrange.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.