guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
measure_glyph.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 <memory>
26#include <string>
27
28#include <utility/ressource_provider.hpp>
29
30#include <utility/cache.hpp>
31
32#include <utility/graphic/text/code_points.hpp>
33
34#include <utility/engine.hpp>
35
36#include "guillaume/ecs/system_filler.hpp"
37
38#include "guillaume/components/bound.hpp"
39#include "guillaume/components/glyph.hpp"
40#include "guillaume/components/transform.hpp"
41#include "guillaume/components/color.hpp"
42
43namespace guillaume::systems
44{
55 std::string glyphName;
56 float fontSize;
59 utility::graphic::Color32Bit
62
68 bool operator==(const MeasureGlyphCacheKey &other) const
69 {
70 if (glyphName != other.glyphName) {
71 return false;
72 }
73 if (fontSize != other.fontSize) {
74 return false;
75 }
76 if (glyphStyle != other.glyphStyle) {
77 return false;
78 }
79 if (color != other.color) {
80 return false;
81 }
82 return true;
83 }
84
90 bool operator!=(const MeasureGlyphCacheKey &other) const
91 {
92 return !(*this == other);
93 }
94
101 bool operator<(const MeasureGlyphCacheKey &other) const
102 {
103 if (glyphName != other.glyphName) {
104 return glyphName < other.glyphName;
105 }
106 if (fontSize != other.fontSize) {
107 return fontSize < other.fontSize;
108 }
109 if (glyphStyle != other.glyphStyle) {
110 return glyphStyle < other.glyphStyle;
111 }
112 if (color != other.color) {
113 return color < other.color;
114 }
115 return false;
116 }
117 };
118
148 public utility::Cache<MeasureGlyphCacheKey, utility::graphic::SizeF>,
149 public ecs::SystemFiller<components::Glyph, components::Bound,
150 components::Transform, components::Color>
151 {
152 private:
153 std::shared_ptr<utility::RessourceProvider>
154 _ressourceProvider;
156 utility::Engine &_engine;
157 std::string _defaultFontPath;
158 std::string _glyphCodePath;
160 std::shared_ptr<utility::graphic::CodePoints>
161 _codePoints;
163 bool _hasFont { false };
164
165 public:
177 std::shared_ptr<utility::RessourceProvider> ressourceProvider,
178 utility::Engine &engine);
179
183 ~MeasureGlyph(void);
184
188 void prepare(void) override;
189
193 void cleanup(void) override;
194
202 virtual void
203 update(const ecs::Entity::Identifier &entityIdentifier) override;
204 };
205
206} // namespace guillaume::systems
Style
Family of the Material Symbols font the icon belongs to.
Definition glyph.hpp:66
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 prepare(void) override
Does nothing: the system needs no per-frame setup.
virtual void update(const ecs::Entity::Identifier &entityIdentifier) override
Write the size of one icon into its components::Bound, measuring it with the engine when it is not in...
~MeasureGlyph(void)
Destroy the system and its cache.
void cleanup(void) override
Does nothing: the cache is kept from one frame to the next.
MeasureGlyph(std::shared_ptr< utility::RessourceProvider > ressourceProvider, utility::Engine &engine)
Create the system in the Measure phase and load the icon font and its code point table.
Rules. Every class here runs each frame on the entities that have the components it declares.
Key of the size cache of MeasureGlyph: everything a measured icon size is looked up by.
bool operator==(const MeasureGlyphCacheKey &other) const
Compare two keys field by field.
components::Glyph::Style glyphStyle
Style of the icon (outlined, rounded, sharp).
utility::graphic::Color32Bit color
std::string glyphName
Name of the icon, such as "home".
float fontSize
Font size the icon was measured at.
bool operator!=(const MeasureGlyphCacheKey &other) const
Negation of operator==.
bool operator<(const MeasureGlyphCacheKey &other) const
Order two keys by name, then font size, then style, then color.