guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
typography.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/typography.hpp"
24
25#include "guillaume/theme.hpp"
26
27namespace guillaume::systems
28{
31 ecs::Phase::Measure)
32 {
33 }
34
36 const ecs::Entity::Identifier &entityIdentifier)
37 {
38 const auto &typography =
39 componentRegistry.getComponent<components::Typography>(
40 entityIdentifier);
41
42 // Fold the explicit size into the token before writing, so the Text
43 // is written once and only marked changed when a metric differs.
44 theme::TypeToken token = getTypeToken(typography.getRole());
45 if (const auto fontSize = typography.getFontSize()) {
46 token.fontSize = *fontSize;
47 }
48
49 componentRegistry.getComponent<components::Text>(entityIdentifier)
50 .setTypeToken(token);
51 }
52
53 void Typography::update(const ecs::Entity::Identifier &entityIdentifier)
54 {
55 if (!requireComponent<components::Typography>(entityIdentifier)
56 || !requireComponent<components::Text>(entityIdentifier)) {
57 return;
58 }
59
60 apply(getComponentRegistry(), entityIdentifier);
61 }
62} // namespace guillaume::systems
A run of text: its content, its font metrics and the position of the editing cursor.
Definition text.hpp:66
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...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
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
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
Definition system.cpp:53
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...
void update(const ecs::Entity::Identifier &entityIdentifier) override
Resolve the metrics of one text for this frame.
Typography(void)
Create the system in the Measure phase.
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
Rules. Every class here runs each frame on the entities that have the components it declares.
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...
One text style: everything needed to measure and draw a piece of text.
Definition typescale.hpp:83