guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
badge.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 <string>
28
29#include <utility/graphic/color.hpp>
30#include <utility/graphic/pose.hpp>
31
32#include "guillaume/ecs/component_registry.hpp"
33#include "guillaume/ecs/entity_builder.hpp"
34
35#include "guillaume/components/animation.hpp"
36#include "guillaume/components/badge.hpp"
37
38#include "guillaume/entities/builder_base.hpp"
39#include "guillaume/entities/surface.hpp"
40#include "guillaume/entities/text.hpp"
41
42namespace guillaume::entities
43{
44
84 class Badge: public SurfaceBase<components::Animation, components::Badge>
85 {
86 public:
90
95 class Builder: public EntityBuilderBase<Badge>
96 {
97 private:
98 SurfaceConfig _config;
99 Variant _variant { Variant::Large };
100 std::string _label {};
101
102 public:
110 Builder(ecs::ComponentRegistry &componentRegistry,
111 ecs::EntityRegistry &entityRegistry);
112
118 std::shared_ptr<Badge> buildEntity(void) override;
119
125 void reset(void) override;
126
133 Builder &withPose(const utility::graphic::PoseF &pose);
134
141 Builder &withVariant(Variant variant);
142
149 Builder &withLabel(const std::string &label);
150
161 std::shared_ptr<Badge>
162 makeBadge(std::shared_ptr<ecs::Entity> parent,
163 const std::string &label, Variant variant);
164 };
165
178 template<typename... Arguments>
179 static std::shared_ptr<Badge> create(Arguments &&...arguments)
180 {
181 std::shared_ptr<Badge> entity(
182 new Badge(std::forward<Arguments>(arguments)...));
183 entity->build();
184 return entity;
185 }
186
190 ~Badge(void) override;
191
199 Badge &setVariant(Variant variant);
200
205 Variant getVariant(void) const;
206
215 Badge &setLabel(const std::string &label);
216
226 Badge &setSize(float size);
227
233 Badge &clearSize(void);
234
240 float getSize(void) const;
241
248 Badge &setContainerColor(const utility::graphic::Color32Bit &color);
249
256 Badge &setContentColor(const utility::graphic::Color32Bit &color);
257
268 Badge &setVisible(bool visible);
269
275 bool isVisible(void) const;
276
282 float getOpacity(void) const;
283
284 private:
294 Badge(ecs::ComponentRegistry &registry, const SurfaceConfig &config,
295 Variant variant, const std::string &label);
296
305 void build(void);
306 };
307
308} // namespace guillaume::entities
Variant
Kind of badge; it sets the height and whether a label is shown.
Definition badge.hpp:70
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
std::shared_ptr< Badge > buildEntity(void) override
Build a badge and its label from the current configuration, without registering it or giving it a par...
Definition badge.cpp:43
Builder & withLabel(const std::string &label)
Set the text shown in the badge.
Definition badge.cpp:74
Builder & withVariant(Variant variant)
Choose the size class of the badge.
Definition badge.cpp:68
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
Definition badge.cpp:36
void reset(void) override
Restore the defaults: default pose, the Large variant, an empty label, and a horizontal layout center...
Definition badge.cpp:49
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the badge is.
Definition badge.cpp:62
std::shared_ptr< Badge > makeBadge(std::shared_ptr< ecs::Entity > parent, const std::string &label, Variant variant)
Build a badge and its label, register it under parent and reset the builder.
Definition badge.cpp:81
A small colored pill showing a count or a short label, or a plain status dot (react-native-paper Badg...
Definition badge.hpp:85
Badge & setSize(float size)
Override the height of the variant (Paper size). Resizes at once.
Definition badge.cpp:134
Badge & setLabel(const std::string &label)
Change the text shown in the badge. Restyles at once.
Definition badge.cpp:125
Badge & setContainerColor(const utility::graphic::Color32Bit &color)
Override the fill color of the pill. Restyles at once.
Definition badge.cpp:155
Badge & clearSize(void)
Drop the height override and use the height of the variant again. Resizes at once.
Definition badge.cpp:146
~Badge(void) override
Destructor.
Definition badge.cpp:100
Badge & setContentColor(const utility::graphic::Color32Bit &color)
Override the color of the label. Restyles at once.
Definition badge.cpp:164
float getOpacity(void) const
Get the current opacity of the fade.
Definition badge.cpp:187
Badge & setVariant(Variant variant)
Change the size class of the badge. Resizes at once.
Definition badge.cpp:109
Variant getVariant(void) const
Get the size class of the badge.
Definition badge.cpp:118
components::Badge::Variant Variant
Definition badge.hpp:89
static std::shared_ptr< Badge > create(Arguments &&...arguments)
Build a badge without registering it in an entity registry.
Definition badge.hpp:179
bool isVisible(void) const
Get the visibility the badge is fading to.
Definition badge.cpp:180
float getSize(void) const
Get the height the badge is drawn with.
Definition badge.cpp:104
Badge & setVisible(bool visible)
Show or hide the badge with a 150 ms fade (Paper visible).
Definition badge.cpp:173
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
SurfaceBase(ecs::ComponentRegistry &registry, const SurfaceConfig &config)
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...
Definition surface.hpp:71