guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
icon.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 <utility/graphic/color.hpp>
28
29#include "guillaume/ecs/component_registry.hpp"
30#include "guillaume/entities/builder_base.hpp"
31#include "guillaume/ecs/entity_builder.hpp"
32#include "guillaume/ecs/entity_filler.hpp"
33
34#include "guillaume/components/accessibility.hpp"
35#include "guillaume/components/glyph.hpp"
36#include "guillaume/components/bound.hpp"
37#include "guillaume/components/transform.hpp"
38#include "guillaume/components/color.hpp"
39
40namespace guillaume::entities
41{
42
77 class Icon:
78 public ecs::EntityFiller<components::Transform, components::Bound,
79 components::Glyph, components::Color>
80 {
81 public:
86 class Builder: public EntityBuilderBase<Icon>
87 {
88 private:
89 std::string _glyphName;
90 float _fontSize;
91 utility::graphic::Color32Bit _color;
93 _style;
94
95 public:
103 Builder(ecs::ComponentRegistry &componentRegistry,
104 ecs::EntityRegistry &entityRegistry);
105
111 std::shared_ptr<Icon> buildEntity(void) override;
112
118 void reset(void) override;
119
127 Builder &withGlyphName(const std::string &glyphName);
128
135 Builder &withFontSize(float fontSize);
136
143 Builder &withColor(const utility::graphic::Color32Bit &color);
144
152
165 std::shared_ptr<Icon>
166 makeIcon(std::shared_ptr<Entity> parent,
167 const std::string &iconName, const float &fontSize,
168 const utility::graphic::Color32Bit &color,
169 const components::Glyph::Style &style);
170 };
171
172 public:
184 template<typename... Arguments>
185 static std::shared_ptr<Icon> create(Arguments &&...arguments)
186 {
187 std::shared_ptr<Icon> entity(
188 new Icon(std::forward<Arguments>(arguments)...));
189 return entity;
190 }
191
195 ~Icon(void);
196
204 Icon &setGlyphName(const std::string &glyphName);
205
213 Icon &setFontSize(const float &fontSize);
214
220 Icon &setColor(const utility::graphic::Color32Bit &color);
221
228
241 Icon &setAccessibilityLabel(const std::string &label);
242
243 private:
253 Icon(ecs::ComponentRegistry &registry, const std::string &glyphName,
254 const float &fontSize, const utility::graphic::Color32Bit &color,
255 const components::Glyph::Style &style);
256 };
257
258} // namespace guillaume::entities
Style
Family of the Material Symbols font the icon belongs to.
Definition glyph.hpp:66
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(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
Builder & withGlyphName(const std::string &glyphName)
Choose the icon to draw.
Definition icon.cpp:54
Builder & withFontSize(float fontSize)
Set the size of the icon.
Definition icon.cpp:60
Builder & withColor(const utility::graphic::Color32Bit &color)
Set the icon color.
Definition icon.cpp:67
Builder & withStyle(const components::Glyph::Style &style)
Set the Material Symbols style of the glyph.
Definition icon.cpp:74
void reset(void) override
Restore the defaults: empty glyph name, font size 24, the OnSurface color of the active theme,...
Definition icon.cpp:46
std::shared_ptr< Icon > makeIcon(std::shared_ptr< Entity > parent, const std::string &iconName, const float &fontSize, const utility::graphic::Color32Bit &color, const components::Glyph::Style &style)
Build an icon, register it under parent and reset the builder.
Definition icon.cpp:80
std::shared_ptr< Icon > buildEntity(void) override
Build an icon from the current configuration, without registering it or giving it a parent.
Definition icon.cpp:39
A Material Symbols icon, chosen by name and drawn as one glyph of the icon font.
Definition icon.hpp:80
Icon & setAccessibilityLabel(const std::string &label)
Give the icon a meaning for assistive technologies.
Definition icon.cpp:135
Icon & setFontSize(const float &fontSize)
Set the size of the icon.
Definition icon.cpp:117
Icon & setStyle(const components::Glyph::Style &style)
Set the Material Symbols style of the glyph.
Definition icon.cpp:152
Icon & setGlyphName(const std::string &glyphName)
Change the icon to draw.
Definition icon.cpp:108
Icon & setColor(const utility::graphic::Color32Bit &color)
Set the icon color.
Definition icon.cpp:126
static std::shared_ptr< Icon > create(Arguments &&...arguments)
Build an icon without registering it in an entity registry.
Definition icon.hpp:185
~Icon(void)
Destructor.
Definition icon.cpp:104
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46