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#pragma once
23
24#include <optional>
25#include <string>
26
27#include <utility/graphic/color.hpp>
28
29#include "guillaume/ecs/component.hpp"
30#include "guillaume/ecs/entity.hpp"
31
33{
34
63 class Badge: public ecs::Component
64 {
65 public:
70 enum class Variant {
74 };
75
77 static constexpr float DotSize = 6.0f;
78
80 static constexpr float SmallSize = 16.0f;
81
83 static constexpr float LargeSize = 20.0f;
84
86 static constexpr float HorizontalPadding = 3.0f;
87
89 static constexpr float LabelScale = 0.5f;
90
91 private:
92 Variant _variant { Variant::Large };
93 std::string _label {};
94 ecs::Entity::Identifier _labelEntity {
96 };
97
98 std::optional<float> _size {};
99 std::optional<utility::graphic::Color32Bit>
100 _containerColor {};
101 std::optional<utility::graphic::Color32Bit>
102 _contentColor {};
103 bool _visible { true };
104 float _opacity { 1.0f };
105 float _fadeFrom { 1.0f };
106
107 public:
111 Badge(void) = default;
112
116 ~Badge(void) = default;
117
122 Variant getVariant(void) const noexcept;
123
129 Badge &setVariant(Variant variant);
130
136 const std::string &getLabel(void) const noexcept;
137
147 Badge &setLabel(const std::string &label);
148
154 ecs::Entity::Identifier getLabelEntity(void) const noexcept;
155
163
169 const std::optional<float> &getSize(void) const noexcept;
170
179 Badge &setSize(std::optional<float> size);
180
185 const std::optional<utility::graphic::Color32Bit> &
186 getContainerColor(void) const noexcept;
187
195 std::optional<utility::graphic::Color32Bit> color);
196
201 const std::optional<utility::graphic::Color32Bit> &
202 getContentColor(void) const noexcept;
203
210 Badge &
211 setContentColor(std::optional<utility::graphic::Color32Bit> color);
212
217 bool isVisible(void) const noexcept;
218
227 Badge &setVisible(bool visible);
228
233 float getOpacity(void) const noexcept;
234
244 Badge &setOpacity(float opacity);
245
250 float getFadeFrom(void) const noexcept;
251
260 Badge &setFadeFrom(float opacity);
261 };
262
263} // namespace guillaume::components
static constexpr float SmallSize
Height of the Small variant, in dp.
Definition badge.hpp:80
Badge & setVisible(bool visible)
Store the visibility the fade heads to.
Definition badge.cpp:122
~Badge(void)=default
Default destructor.
Badge & setLabelEntity(ecs::Entity::Identifier identifier)
Record which child entity draws the label.
Definition badge.cpp:62
const std::string & getLabel(void) const noexcept
Get the label text.
Definition badge.cpp:43
Variant
Kind of badge; it sets the height and whether a label is shown.
Definition badge.hpp:70
@ Small
16 dp high badge with a label.
Definition badge.hpp:72
@ Large
20 dp high badge with a label (the default).
Definition badge.hpp:73
@ Dot
6 dp dot without label.
Definition badge.hpp:71
ecs::Entity::Identifier getLabelEntity(void) const noexcept
Get the child entity that draws the label.
Definition badge.cpp:57
Badge & setSize(std::optional< float > size)
Replace the height of the variant.
Definition badge.cpp:76
Badge(void)=default
Create the state of a visible Large badge with no label.
const std::optional< utility::graphic::Color32Bit > & getContentColor(void) const noexcept
Get the color that replaces the themed label color.
Definition badge.cpp:102
Badge & setVariant(Variant variant)
Choose the kind of badge.
Definition badge.cpp:34
Badge & setFadeFrom(float opacity)
Record the opacity a fade starts from.
Definition badge.cpp:150
Badge & setOpacity(float opacity)
Set the opacity the badge is drawn with.
Definition badge.cpp:136
bool isVisible(void) const noexcept
Check whether the badge is shown or fading in.
Definition badge.cpp:117
const std::optional< float > & getSize(void) const noexcept
Get the height that replaces the one of the variant.
Definition badge.cpp:71
Badge & setContentColor(std::optional< utility::graphic::Color32Bit > color)
Replace the themed label color.
Definition badge.cpp:107
float getOpacity(void) const noexcept
Get the opacity the badge is drawn with.
Definition badge.cpp:131
static constexpr float LargeSize
Height of the Large variant, in dp.
Definition badge.hpp:83
Badge & setLabel(const std::string &label)
Set the label text.
Definition badge.cpp:48
static constexpr float LabelScale
Label font size as a fraction of the badge height.
Definition badge.hpp:89
static constexpr float DotSize
Height of the Dot variant, in dp.
Definition badge.hpp:77
Variant getVariant(void) const noexcept
Get the kind of badge.
Definition badge.cpp:29
static constexpr float HorizontalPadding
Space on each side of the label, in dp.
Definition badge.hpp:86
float getFadeFrom(void) const noexcept
Get the opacity the running fade started from.
Definition badge.cpp:145
Badge & setContainerColor(std::optional< utility::graphic::Color32Bit > color)
Replace the themed container (background) color.
Definition badge.cpp:91
const std::optional< utility::graphic::Color32Bit > & getContainerColor(void) const noexcept
Get the color that replaces the themed container color.
Definition badge.cpp:86
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
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
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
State. Every class here is plain data attached to an entity.