guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::components::Badge Class Reference

State of a badge: a small dot or pill, usually holding a count, drawn over another widget. More...

#include <headers/guillaume/components/badge.hpp>

Inheritance diagram for guillaume::components::Badge:
Collaboration diagram for guillaume::components::Badge:

Public Types

enum class  Variant { Dot , Small , Large }
 Kind of badge; it sets the height and whether a label is shown. More...

Public Member Functions

 Badge (void)=default
 Create the state of a visible Large badge with no label.
 ~Badge (void)=default
 Default destructor.
Variant getVariant (void) const noexcept
 Get the kind of badge.
Badge & setVariant (Variant variant)
 Choose the kind of badge.
const std::string & getLabel (void) const noexcept
 Get the label text.
Badge & setLabel (const std::string &label)
 Set the label text.
ecs::Entity::Identifier getLabelEntity (void) const noexcept
 Get the child entity that draws the label.
Badge & setLabelEntity (ecs::Entity::Identifier identifier)
 Record which child entity draws the label.
const std::optional< float > & getSize (void) const noexcept
 Get the height that replaces the one of the variant.
Badge & setSize (std::optional< float > size)
 Replace the height of the variant.
const std::optional< utility::graphic::Color32Bit > & getContainerColor (void) const noexcept
 Get the color that replaces the themed container color.
Badge & setContainerColor (std::optional< utility::graphic::Color32Bit > color)
 Replace the themed container (background) color.
const std::optional< utility::graphic::Color32Bit > & getContentColor (void) const noexcept
 Get the color that replaces the themed label color.
Badge & setContentColor (std::optional< utility::graphic::Color32Bit > color)
 Replace the themed label color.
bool isVisible (void) const noexcept
 Check whether the badge is shown or fading in.
Badge & setVisible (bool visible)
 Store the visibility the fade heads to.
float getOpacity (void) const noexcept
 Get the opacity the badge is drawn with.
Badge & setOpacity (float opacity)
 Set the opacity the badge is drawn with.
float getFadeFrom (void) const noexcept
 Get the opacity the running fade started from.
Badge & setFadeFrom (float opacity)
 Record the opacity a fade starts from.
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Static Public Attributes

static constexpr float DotSize = 6.0f
 Height of the Dot variant, in dp.
static constexpr float SmallSize = 16.0f
 Height of the Small variant, in dp.
static constexpr float LargeSize = 20.0f
 Height of the Large variant, in dp.
static constexpr float HorizontalPadding = 3.0f
 Space on each side of the label, in dp.
static constexpr float LabelScale = 0.5f
 Label font size as a fraction of the badge height.

Detailed Description

State of a badge: a small dot or pill, usually holding a count, drawn over another widget.

It holds the variant, the label, the size and color overrides, the identifier of the label child, and the state of the fade that shows or hides the badge.

Role in the frame:

Watch out:

Every setter compares before writing and marks the component changed only when the value differs.

See also
systems::Badge, components::Animation

Definition at line 63 of file badge.hpp.

Member Enumeration Documentation

◆ Variant

Kind of badge; it sets the height and whether a label is shown.

Enumerator
Dot 

6 dp dot without label.

Small 

16 dp high badge with a label.

Large 

20 dp high badge with a label (the default).

Definition at line 70 of file badge.hpp.

Member Function Documentation

◆ getContainerColor()

const std::optional< utility::graphic::Color32Bit > & guillaume::components::Badge::getContainerColor ( void ) const
noexcept

Get the color that replaces the themed container color.

Returns
The color, or std::nullopt when the theme decides.

Definition at line 86 of file badge.cpp.

◆ getContentColor()

const std::optional< utility::graphic::Color32Bit > & guillaume::components::Badge::getContentColor ( void ) const
noexcept

Get the color that replaces the themed label color.

Returns
The color, or std::nullopt when the theme decides.

Definition at line 102 of file badge.cpp.

◆ getFadeFrom()

float guillaume::components::Badge::getFadeFrom ( void ) const
noexcept

Get the opacity the running fade started from.

Returns
The starting opacity, 0 to 1.

Definition at line 145 of file badge.cpp.

◆ getLabel()

const std::string & guillaume::components::Badge::getLabel ( void ) const
noexcept

Get the label text.

Returns
The text, typically a count such as "3" or "99+"; empty for none.

Definition at line 43 of file badge.cpp.

◆ getLabelEntity()

ecs::Entity::Identifier guillaume::components::Badge::getLabelEntity ( void ) const
noexcept

Get the child entity that draws the label.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when the badge has no label child.

Definition at line 57 of file badge.cpp.

◆ getOpacity()

float guillaume::components::Badge::getOpacity ( void ) const
noexcept

Get the opacity the badge is drawn with.

Returns
The opacity, 0 (hidden) to 1 (fully shown).

Definition at line 131 of file badge.cpp.

◆ getSize()

const std::optional< float > & guillaume::components::Badge::getSize ( void ) const
noexcept

Get the height that replaces the one of the variant.

Returns
The height, in dp, or std::nullopt when the variant decides. Use systems::Badge::sizeOf() for the height really used.

Definition at line 71 of file badge.cpp.

◆ getVariant()

Badge::Variant guillaume::components::Badge::getVariant ( void ) const
noexcept

Get the kind of badge.

Returns
The variant (Large by default).

Definition at line 29 of file badge.cpp.

Here is the caller graph for this function:

◆ isVisible()

bool guillaume::components::Badge::isVisible ( void ) const
noexcept

Check whether the badge is shown or fading in.

Returns
True when the badge is, or is becoming, visible.

Definition at line 117 of file badge.cpp.

Here is the caller graph for this function:

◆ setContainerColor()

Badge & guillaume::components::Badge::setContainerColor ( std::optional< utility::graphic::Color32Bit > color)

Replace the themed container (background) color.

Parameters
colorThe container color, or std::nullopt to follow the theme (the error color).
Returns
This component, for chaining.

Definition at line 91 of file badge.cpp.

Here is the call graph for this function:

◆ setContentColor()

Badge & guillaume::components::Badge::setContentColor ( std::optional< utility::graphic::Color32Bit > color)

Replace the themed label color.

Parameters
colorThe label color, or std::nullopt to follow the theme (the on-error color).
Returns
This component, for chaining.

Definition at line 107 of file badge.cpp.

Here is the call graph for this function:

◆ setFadeFrom()

Badge & guillaume::components::Badge::setFadeFrom ( float opacity)

Record the opacity a fade starts from.

Written by systems::Badge::setVisible(), so a fade interrupted half-way reverses from where it was.

Parameters
opacityThe starting opacity, 0 to 1.
Returns
This component, for chaining.

Definition at line 150 of file badge.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLabel()

Badge & guillaume::components::Badge::setLabel ( const std::string & label)

Set the label text.

The system copies it to the label child. A label wider than the badge height stretches the badge into a pill. The Dot variant shows no label.

Parameters
labelThe label text.
Returns
This component, for chaining.

Definition at line 48 of file badge.cpp.

Here is the call graph for this function:

◆ setLabelEntity()

Badge & guillaume::components::Badge::setLabelEntity ( ecs::Entity::Identifier identifier)

Record which child entity draws the label.

Parameters
identifierThe label child, or ecs::Entity::InvalidIdentifier for none.
Returns
This component, for chaining.

Definition at line 62 of file badge.cpp.

Here is the call graph for this function:

◆ setOpacity()

Badge & guillaume::components::Badge::setOpacity ( float opacity)

Set the opacity the badge is drawn with.

Written by systems::Badge on each sample of the fade. The system multiplies the alpha of the container and label colors by it. The value is stored as given, without clamping.

Parameters
opacityThe opacity, 0 (hidden) to 1 (fully shown).
Returns
This component, for chaining.

Definition at line 136 of file badge.cpp.

Here is the call graph for this function:

◆ setSize()

Badge & guillaume::components::Badge::setSize ( std::optional< float > size)

Replace the height of the variant.

The label font size follows: it is LabelScale times the height.

Parameters
sizeThe height, in dp, or std::nullopt to follow the variant.
Returns
This component, for chaining.

Definition at line 76 of file badge.cpp.

Here is the call graph for this function:

◆ setVariant()

Badge & guillaume::components::Badge::setVariant ( Variant variant)

Choose the kind of badge.

Parameters
variantDot, Small or Large.
Returns
This component, for chaining.

Definition at line 34 of file badge.cpp.

Here is the call graph for this function:

◆ setVisible()

Badge & guillaume::components::Badge::setVisible ( bool visible)

Store the visibility the fade heads to.

It starts no fade and leaves the opacity untouched; use systems::Badge::setVisible() to show or hide the badge.

Parameters
visibleTrue when the badge should end up shown.
Returns
This component, for chaining.

Definition at line 122 of file badge.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ DotSize

float guillaume::components::Badge::DotSize = 6.0f
staticconstexpr

Height of the Dot variant, in dp.

Definition at line 77 of file badge.hpp.

◆ HorizontalPadding

float guillaume::components::Badge::HorizontalPadding = 3.0f
staticconstexpr

Space on each side of the label, in dp.

Definition at line 86 of file badge.hpp.

◆ LabelScale

float guillaume::components::Badge::LabelScale = 0.5f
staticconstexpr

Label font size as a fraction of the badge height.

Definition at line 89 of file badge.hpp.

◆ LargeSize

float guillaume::components::Badge::LargeSize = 20.0f
staticconstexpr

Height of the Large variant, in dp.

Definition at line 83 of file badge.hpp.

◆ SmallSize

float guillaume::components::Badge::SmallSize = 16.0f
staticconstexpr

Height of the Small variant, in dp.

Definition at line 80 of file badge.hpp.


The documentation for this class was generated from the following files: