guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
text_field.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 <string>
26
27#include "guillaume/ecs/system_filler.hpp"
28
29#include "guillaume/components/text.hpp"
30#include "guillaume/components/text_field.hpp"
31#include "guillaume/components/text_field_configuration.hpp"
32#include "guillaume/theme/tokens.hpp"
33
34namespace guillaume::systems
35{
36
83 class TextField: public ecs::SystemFiller<components::TextField>
84 {
85 public:
87 static constexpr float Height = 56.0f;
88
90 static constexpr float DenseLabelHeight = 52.0f;
91
93 static constexpr float DenseHeight = 40.0f;
94
97 static constexpr float Padding = theme::SpacingScale::get(4);
98
100 static constexpr float Spacing = theme::SpacingScale::get(3);
101
104 static constexpr float SupportingGap = theme::SpacingScale::get(1);
105
108 static constexpr float IconSize = 24.0f;
109
113 TextField(void);
114
118 ~TextField(void) override = default;
119
135 static void install(ecs::ComponentRegistry &componentRegistry,
136 const ecs::Entity::Identifier &entityIdentifier);
137
164 static void apply(ecs::ComponentRegistry &componentRegistry,
165 const ecs::Entity::Identifier &entityIdentifier);
166
181 static void
182 applyContainer(ecs::ComponentRegistry &componentRegistry,
183 const ecs::Entity::Identifier &entityIdentifier);
184
196 static void
197 applyEditing(ecs::ComponentRegistry &componentRegistry,
198 const ecs::Entity::Identifier &entityIdentifier);
199
208 static bool isFocused(const ecs::ComponentRegistry &componentRegistry,
209 const ecs::Entity::Identifier &entityIdentifier);
210
217 static bool isDisabled(const ecs::ComponentRegistry &componentRegistry,
218 const ecs::Entity::Identifier &entityIdentifier);
219
226 static bool
227 isLabelFloating(const ecs::ComponentRegistry &componentRegistry,
228 const ecs::Entity::Identifier &entityIdentifier);
229
238 static std::string
239 text(const ecs::ComponentRegistry &componentRegistry,
240 const ecs::Entity::Identifier &entityIdentifier);
241
252 static void setText(ecs::ComponentRegistry &componentRegistry,
253 const ecs::Entity::Identifier &entityIdentifier,
254 const std::string &text);
255
265 static void setDisabled(ecs::ComponentRegistry &componentRegistry,
266 const ecs::Entity::Identifier &entityIdentifier,
267 bool disabled);
268
277 static std::string
278 supportingText(const ecs::ComponentRegistry &componentRegistry,
279 const ecs::Entity::Identifier &entityIdentifier);
280
292 void update(const ecs::Entity::Identifier &entityIdentifier) override;
293
306 static bool reconcile(components::TextField &textField,
307 bool hasContent);
308 };
309
310} // namespace guillaume::systems
The texts around the input of a text field, and its error state: placeholder, label,...
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
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
The base class to derive a system from: a System whose signature is the list of component types given...
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.
~TextField(void) override=default
Default destructor.
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 constexpr float get(unsigned int steps)
Get a spacing as a number of grid units.
Definition tokens.hpp:441
Rules. Every class here runs each frame on the entities that have the components it declares.