guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
text.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 <utility>
26#include <memory>
27#include "guillaume/ecs/component_registry.hpp"
28#include "guillaume/entities/builder_base.hpp"
29#include "guillaume/ecs/entity_builder.hpp"
30#include "guillaume/ecs/entity_filler.hpp"
31
32#include "guillaume/components/bound.hpp"
33#include "guillaume/components/text.hpp"
34#include "guillaume/components/typography.hpp"
35#include "guillaume/components/transform.hpp"
36#include "guillaume/components/color.hpp"
37
38#include "guillaume/theme/typescale.hpp"
39
40#include <optional>
41
42namespace guillaume::entities
43{
44
81 class Text:
82 public ecs::EntityFiller<components::Transform, components::Bound,
83 components::Text, components::Color,
84 components::Typography>
85 {
86 public:
91 enum class Type { Normal, Condensed, Monospace, Serif, Slab };
92
97 class Builder: public EntityBuilderBase<Text>
98 {
99 public:
100 private:
101 std::string _content;
102 theme::TypeRole _typeRole;
103 std::optional<float>
104 _fontSize;
106 utility::graphic::Color32Bit _color;
107
108 public:
116 Builder(ecs::ComponentRegistry &componentRegistry,
117 ecs::EntityRegistry &entityRegistry);
118
124 std::shared_ptr<Text> buildEntity(void) override;
125
131 void reset(void) override;
132
138 Builder &withContent(const std::string &content);
139
149 Builder &withFontSize(const float &fontSize);
150
159
166 Builder &withColor(const utility::graphic::Color32Bit &color);
167
182 std::shared_ptr<Text>
183 makeText(std::shared_ptr<Entity> parent,
184 const std::string &content, const float &fontSize,
185 const utility::graphic::Color32Bit &color);
186
198 std::shared_ptr<Text>
199 makeText(std::shared_ptr<Entity> parent,
200 const std::string &content, theme::TypeRole role,
201 const utility::graphic::Color32Bit &color);
202 };
203
204 public:
217 template<typename... Arguments>
218 static std::shared_ptr<Text> create(Arguments &&...arguments)
219 {
220 std::shared_ptr<Text> entity(
221 new Text(std::forward<Arguments>(arguments)...));
222 return entity;
223 }
224
228 ~Text(void);
229
238 Text &setContent(const std::string &content);
239
249 Text &setFontSize(const float &fontSize);
250
261
266 theme::TypeRole getTypeRole(void) const;
267
273 Text &setColor(const utility::graphic::Color32Bit &color);
274
275 private:
280 components::Typography &typography(void);
281
286 const components::Typography &typography(void) const;
287
293 void applyTypography(void);
294
295 private:
304 Text(ecs::ComponentRegistry &registry, const std::string &content,
305 const float &fontSize, const utility::graphic::Color32Bit &color);
306
316 Text(ecs::ComponentRegistry &registry, const std::string &content,
317 theme::TypeRole role, const utility::graphic::Color32Bit &color,
318 std::optional<float> fontSize = std::nullopt);
319 };
320
321} // namespace guillaume::entities
Which typescale role a text uses (BodyMedium, TitleLarge, ...) and an optional explicit size.
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
The base class of a widget without children: an Entity that creates its components when it is constru...
Owns entities and gives the systems the list of entities to visit.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Builder & withFontSize(const float &fontSize)
Override the role font size with an explicit size.
Definition text.cpp:61
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
std::shared_ptr< Text > buildEntity(void) override
Build a text from the current configuration, without registering it or giving it a parent.
Definition text.cpp:40
void reset(void) override
Restore the defaults: empty content, role BodyMedium, no explicit font size, and the OnSurface color ...
Definition text.cpp:47
Builder & withTypeRole(theme::TypeRole role)
Set the typescale role and drop any explicit font size.
Definition text.cpp:67
std::shared_ptr< Text > makeText(std::shared_ptr< Entity > parent, const std::string &content, const float &fontSize, const utility::graphic::Color32Bit &color)
Build a text with an explicit font size, register it under parent and reset the builder.
Definition text.cpp:81
Builder & withContent(const std::string &content)
Set the characters to draw.
Definition text.cpp:55
Builder & withColor(const utility::graphic::Color32Bit &color)
Set the text color.
Definition text.cpp:75
A single run of text drawn with a typescale role, a color and an optional explicit font size.
Definition text.hpp:85
Type
Font family kinds. No function of the library reads this enumeration.
Definition text.hpp:91
Text & setContent(const std::string &content)
Replace the characters to draw.
Definition text.cpp:141
~Text(void)
Destructor.
Definition text.cpp:120
theme::TypeRole getTypeRole(void) const
Get the typescale role the text is styled with.
Definition text.cpp:163
Text & setFontSize(const float &fontSize)
Override the role font size with an explicit size.
Definition text.cpp:149
Text & setTypeRole(theme::TypeRole role)
Set the typescale role and drop any explicit font size.
Definition text.cpp:156
static std::shared_ptr< Text > create(Arguments &&...arguments)
Build a text without registering it in an entity registry.
Definition text.hpp:218
Text & setColor(const utility::graphic::Color32Bit &color)
Set the text color.
Definition text.cpp:168
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
TypeRole
The named text styles of Material Design 3: what a piece of text is, not how big it is.
Definition typescale.hpp:47