guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
icon.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 <memory>
24
25#include "guillaume/entities/icon.hpp"
26#include "guillaume/theme.hpp"
27#include "guillaume/entities/builder_base.hpp"
28
29namespace guillaume::entities
30{
31
32 Icon::Icon::Builder::Builder(ecs::ComponentRegistry &componentRegistry,
33 ecs::EntityRegistry &entityRegistry)
34 : EntityBuilderBase<Icon>(componentRegistry, entityRegistry)
35 {
36 reset();
37 }
38
39 std::shared_ptr<Icon> Icon::Builder::buildEntity(void)
40 {
41 auto entity = Icon::create(this->getComponentRegistry(), _glyphName,
42 _fontSize, _color, _style);
43 return entity;
44 }
45
47 {
48 _glyphName.clear();
49 _fontSize = 24.0f;
50 _color = getActiveColor(SchemeColorRole::OnSurface);
51 _style = components::Glyph::Style::Outlined;
52 }
53
54 Icon::Builder &Icon::Builder::withGlyphName(const std::string &glyphName)
55 {
56 _glyphName = glyphName;
57 return *this;
58 }
59
61 {
62 _fontSize = fontSize;
63 return *this;
64 }
65
67 Icon::Builder::withColor(const utility::graphic::Color32Bit &color)
68 {
69 _color = color;
70 return *this;
71 }
72
75 {
76 _style = style;
77 return *this;
78 }
79
80 std::shared_ptr<Icon> Icon::Builder::makeIcon(
81 std::shared_ptr<Entity> parent, const std::string &glyphName,
82 const float &fontSize, const utility::graphic::Color32Bit &color,
83 const components::Glyph::Style &style)
84 {
85 return withGlyphName(glyphName)
86 .withFontSize(fontSize)
87 .withColor(color)
88 .withStyle(style)
89 .registerEntity(parent);
90 }
91
92 Icon::Icon(ecs::ComponentRegistry &registry, const std::string &glyphName,
93 const float &fontSize, const utility::graphic::Color32Bit &color,
94 const components::Glyph::Style &style)
95 : ecs::EntityFiller<components::Transform, components::Bound,
96 components::Glyph, components::Color>(registry)
97 {
98 setGlyphName(glyphName);
99 setFontSize(fontSize);
100 setColor(color);
101 setStyle(style);
102 }
103
105 {
106 }
107
108 Icon &Icon::setGlyphName(const std::string &glyphName)
109 {
112 .setName(glyphName);
113
114 return *this;
115 }
116
117 Icon &Icon::setFontSize(const float &fontSize)
118 {
121 .setFontSize(fontSize);
122
123 return *this;
124 }
125
126 Icon &Icon::setColor(const utility::graphic::Color32Bit &color)
127 {
130 .setColor(color);
131
132 return *this;
133 }
134
135 Icon &Icon::setAccessibilityLabel(const std::string &label)
136 {
137 auto &registry = getComponentRegistry();
138 if (!registry.hasComponent<components::Accessibility>(
139 getIdentifier())) {
140 if (label.empty()) {
141 return *this;
142 }
143 registry.addComponent<components::Accessibility>(getIdentifier());
144 }
145 registry.getComponent<components::Accessibility>(getIdentifier())
146 .setRole(label.empty() ? components::AccessibilityRole::None
148 .setLabel(label);
149 return *this;
150 }
151
153 {
156 .setStyle(style);
157
158 return *this;
159 }
160
161} // namespace guillaume::entities
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setLabel(const std::string &label)
Set the name announced for the entity, such as "Close".
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Definition color.hpp:58
An icon: one glyph of the Material Symbols font, chosen by name, at a given size.
Definition glyph.hpp:61
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...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
Definition entity.cpp:94
Base of every widget Builder: turns a configuration into a widget that is attached to a parent and ow...
Configures Icon widgets and registers them in the scene's entity registry.
Definition icon.hpp:87
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
State. Every class here is plain data attached to an entity.
@ None
No semantic role (decorative or container).
@ Image
Image or icon with meaning.
The entity-component-system core, independent of any widget.
Definition component.hpp:28
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
utility::graphic::Color32Bit getActiveColor(SchemeColorRole role)
Get the color the active scheme gives to a role.