guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
badge.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 "guillaume/components/badge.hpp"
24
25#include <utility>
26
28{
29 Badge::Variant Badge::getVariant(void) const noexcept
30 {
31 return _variant;
32 }
33
35 {
36 if (_variant != variant) {
37 _variant = variant;
38 setHasChanged(true);
39 }
40 return *this;
41 }
42
43 const std::string &Badge::getLabel(void) const noexcept
44 {
45 return _label;
46 }
47
48 Badge &Badge::setLabel(const std::string &label)
49 {
50 if (_label != label) {
51 _label = label;
52 setHasChanged(true);
53 }
54 return *this;
55 }
56
58 {
59 return _labelEntity;
60 }
61
63 {
64 if (_labelEntity != identifier) {
65 _labelEntity = identifier;
66 setHasChanged(true);
67 }
68 return *this;
69 }
70
71 const std::optional<float> &Badge::getSize(void) const noexcept
72 {
73 return _size;
74 }
75
76 Badge &Badge::setSize(std::optional<float> size)
77 {
78 if (_size != size) {
79 _size = size;
80 setHasChanged(true);
81 }
82 return *this;
83 }
84
85 const std::optional<utility::graphic::Color32Bit> &
86 Badge::getContainerColor(void) const noexcept
87 {
88 return _containerColor;
89 }
90
92 std::optional<utility::graphic::Color32Bit> color)
93 {
94 if (_containerColor != color) {
95 _containerColor = color;
96 setHasChanged(true);
97 }
98 return *this;
99 }
100
101 const std::optional<utility::graphic::Color32Bit> &
102 Badge::getContentColor(void) const noexcept
103 {
104 return _contentColor;
105 }
106
108 std::optional<utility::graphic::Color32Bit> color)
109 {
110 if (_contentColor != color) {
111 _contentColor = color;
112 setHasChanged(true);
113 }
114 return *this;
115 }
116
117 bool Badge::isVisible(void) const noexcept
118 {
119 return _visible;
120 }
121
123 {
124 if (_visible != visible) {
125 _visible = visible;
126 setHasChanged(true);
127 }
128 return *this;
129 }
130
131 float Badge::getOpacity(void) const noexcept
132 {
133 return _opacity;
134 }
135
136 Badge &Badge::setOpacity(float opacity)
137 {
138 if (_opacity != opacity) {
139 _opacity = opacity;
140 setHasChanged(true);
141 }
142 return *this;
143 }
144
145 float Badge::getFadeFrom(void) const noexcept
146 {
147 return _fadeFrom;
148 }
149
150 Badge &Badge::setFadeFrom(float opacity)
151 {
152 if (_fadeFrom != opacity) {
153 _fadeFrom = opacity;
154 setHasChanged(true);
155 }
156 return *this;
157 }
158} // namespace guillaume::components
Badge & setVisible(bool visible)
Store the visibility the fade heads to.
Definition badge.cpp:122
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
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
Badge & setLabel(const std::string &label)
Set the label text.
Definition badge.cpp:48
Variant getVariant(void) const noexcept
Get the kind of badge.
Definition badge.cpp:29
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
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
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
State. Every class here is plain data attached to an entity.