guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
measure_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 "guillaume/theme/typescale.hpp"
26#include <string>
27
28#include <utility/cache.hpp>
29
30#include <utility/engine.hpp>
31
32#include "guillaume/ecs/system_filler.hpp"
33
34#include "guillaume/components/bound.hpp"
35#include "guillaume/components/text.hpp"
36#include "guillaume/components/transform.hpp"
37#include "guillaume/components/color.hpp"
38
39namespace guillaume::systems
40{
51 std::string content;
52 float fontSize;
53 utility::graphic::Color32Bit
59
66 bool operator==(const MeasureTextCacheKey &other) const
67 {
68 if (content != other.content) {
69 return false;
70 }
71 if (fontSize != other.fontSize) {
72 return false;
73 }
74 if (color != other.color) {
75 return false;
76 }
77 if (fontWeight != other.fontWeight) {
78 return false;
79 }
80 return true;
81 }
82
88 bool operator!=(const MeasureTextCacheKey &other) const
89 {
90 return !(*this == other);
91 }
92
99 bool operator<(const MeasureTextCacheKey &other) const
100 {
101 if (content != other.content) {
102 return content < other.content;
103 }
104 if (fontSize != other.fontSize) {
105 return fontSize < other.fontSize;
106 }
107 if (color != other.color) {
108 return color < other.color;
109 }
110 return fontWeight < other.fontWeight;
111 }
112 };
113
144 public utility::Cache<MeasureTextCacheKey, utility::graphic::SizeF>,
145 public ecs::SystemFiller<components::Text, components::Bound,
146 components::Transform, components::Color>
147 {
148 private:
149 std::shared_ptr<utility::RessourceProvider>
150 _ressourceProvider;
152 utility::Engine &_engine;
153 std::string _defaultFontPath;
156
157 public:
166 std::shared_ptr<utility::RessourceProvider> ressourceProvider,
167 utility::Engine &engine);
168
172 ~MeasureText(void);
173
177 void prepare(void) override;
178
182 void cleanup(void) override;
183
190 virtual void
191 update(const ecs::Entity::Identifier &entityIdentifier) override;
192 };
193
194} // namespace guillaume::systems
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...
void cleanup(void) override
Does nothing: the cache is kept from one frame to the next.
MeasureText(std::shared_ptr< utility::RessourceProvider > ressourceProvider, utility::Engine &engine)
Create the system in the Measure phase, with an empty cache.
virtual void update(const ecs::Entity::Identifier &entityIdentifier) override
Write the size of one text into its components::Bound, measuring it with the engine when it is not in...
~MeasureText(void)
Destroy the system and its cache.
void prepare(void) override
Does nothing: the system needs no per-frame setup.
Rules. Every class here runs each frame on the entities that have the components it declares.
FontWeight
Font weights available to the typescale. The value is the usual numeric weight (400 regular,...
Definition typescale.hpp:71
Key of the size cache of MeasureText: everything a measured size is looked up by.
float fontSize
Font size the string was measured at.
bool operator<(const MeasureTextCacheKey &other) const
Order two keys by content, then font size, then color, then font weight.
theme::FontWeight fontWeight
Font weight, which selects the font file measured with.
utility::graphic::Color32Bit color
std::string content
The string that was measured.
bool operator==(const MeasureTextCacheKey &other) const
Compare two keys field by field.
bool operator!=(const MeasureTextCacheKey &other) const
Negation of operator==.