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

Sizes and colors a badge (the small dot or counter drawn over another widget) and fades it in and out. More...

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

Inheritance diagram for guillaume::systems::Badge:
Collaboration diagram for guillaume::systems::Badge:

Public Member Functions

 Badge (void)
 Create the system in the Layout phase.
 ~Badge (void) override=default
 Default destructor.
void update (const ecs::Entity::Identifier &entityIdentifier) override
 Run apply() on one badge; called by the frame loop.
Public Member Functions inherited from guillaume::ecs::SystemFiller< components::Badge >
 SystemFiller (Phase phase)
 Create the system and set its signature from ComponentTypes.
virtual ~SystemFiller (void)=default
 Virtual destructor.
Public Member Functions inherited from guillaume::ecs::System
 System (Phase phase)
 Create a system that runs in a given phase, with an empty signature.
virtual ~System (void)=default
 Virtual destructor.
Phase getPhase (void) const noexcept
 Get the phase of the frame in which the system runs.
Entity::Signature getSignature (void) const noexcept
 Get the component types an entity must declare to be visited by this system.
void routine (ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry, const ecs::EntityTreeTraveler &traveler)
 Run the system once over a scene: prepare(), update() on each matching entity, cleanup().
void bindComponentRegistry (ecs::ComponentRegistry &componentRegistry)
 Bind a component registry so update() can be called directly, without routine().
void unbindComponentRegistry (void)
 Drop the binding made by bindComponentRegistry().
virtual void prepare (void)
 Called once per pass, before the first update().
virtual void cleanup (void)
 Called once per pass, after the last update().

Static Public Member Functions

static void install (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Prepare the visibility fade of a badge.
static void apply (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Size and color one badge and its label.
static float sizeOf (const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Get the height of a badge, in dp.
static bool needsLabel (const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Whether the badge should have a label child.
static void setVisible (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool visible)
 Show or hide the badge with a fade.
static void fade (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, float progress)
 Move the visibility fade to a given progress and restyle.

Additional Inherited Members

Protected Member Functions inherited from guillaume::ecs::System
template<InheritFromComponent... ComponentTypes>
void setSignature (void)
 Replace the signature by the one made of the given component types.
ecs::EntityRegistry & getEntityRegistry (void)
 Get the entity registry of the scene being processed.
const ecs::EntityRegistry & getEntityRegistry (void) const
 Get the entity registry of the scene being processed, read-only.
ecs::ComponentRegistry & getComponentRegistry (void)
 Get the component registry of the scene being processed.
const ecs::ComponentRegistry & getComponentRegistry (void) const
 Get the component registry of the scene being processed, read-only.
template<InheritFromComponent ComponentType>
bool hasComponent (const ecs::Entity::Identifier &entityIdentifier) const
 Tell whether an entity has a component, in the bound registry.
template<InheritFromComponent ComponentType>
ComponentType & getComponent (const ecs::Entity::Identifier &entityIdentifier)
 Get a component of an entity from the bound registry, to read or modify it.
template<InheritFromComponent ComponentType>
const ComponentType & getComponent (const ecs::Entity::Identifier &entityIdentifier) const
 Get a component of an entity from the bound registry, read-only.
template<InheritFromComponent ComponentType>
bool requireComponent (const ecs::Entity::Identifier &entityIdentifier)
 Tell whether an entity has a component, and log a warning naming the entity and the component when it does not.

Detailed Description

Sizes and colors a badge (the small dot or counter drawn over another widget) and fades it in and out.

Runs in the Layout phase on every entity that has a components::Badge. It is registered after systems::Layout, so the label is already measured when the badge is sized around it.

Visibility is an opacity from 0 to 1 stored in components::Badge and multiplied into the alpha of both colors. setVisible() starts the badge's components::Animation, whose samples call fade().

// On an entity that has Badge, Animation, Layout, Borders and Color:
systems::Badge::install(registry, badge);
systems::Badge::apply(registry, badge);
systems::Badge::setVisible(registry, badge, false); // fades out
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Size and color one badge and its label.
Definition badge.cpp:166
static void setVisible(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool visible)
Show or hide the badge with a fade.
Definition badge.cpp:138
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Prepare the visibility fade of a badge.
Definition badge.cpp:95
See also
components::Badge, entities::Badge, systems::Animation

Definition at line 60 of file badge.hpp.

Constructor & Destructor Documentation

◆ Badge()

guillaume::systems::Badge::Badge ( void )

Create the system in the Layout phase.

Definition at line 90 of file badge.cpp.

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

Member Function Documentation

◆ apply()

void guillaume::systems::Badge::apply ( ecs::ComponentRegistry & componentRegistry,
const ecs::Entity::Identifier & entityIdentifier )
static

Size and color one badge and its label.

This is what update() runs each frame. Call it directly after changing components::Badge to see the result before the next frame, which is what the setters of entities::Badge do.

The badge is sizeOf() high. It is as wide as it is high, except that a label wider than that grows it into a pill with components::Badge::HorizontalPadding on each side. The label font size is half the badge height. The colors default to the theme's error and onError roles.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe badge entity.
Exceptions
ecs::EntityComponentNotFoundExceptionWhen the entity lacks components::Badge, Layout, Borders or Color.

Definition at line 166 of file badge.cpp.

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

◆ fade()

void guillaume::systems::Badge::fade ( ecs::ComponentRegistry & componentRegistry,
const ecs::Entity::Identifier & entityIdentifier,
float progress )
static

Move the visibility fade to a given progress and restyle.

Called by the animation sample handler wired by install(). Sets the opacity between the value recorded by setVisible() and the target (1 when visible, 0 when hidden), then calls apply().

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe badge entity.
progressEased progress of the fade, from 0 (start) to 1 (target reached).

Definition at line 153 of file badge.cpp.

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

◆ install()

void guillaume::systems::Badge::install ( ecs::ComponentRegistry & componentRegistry,
const ecs::Entity::Identifier & entityIdentifier )
static

Prepare the visibility fade of a badge.

Sets the duration and easing of the entity's components::Animation from the theme and makes each of its samples call fade(). Call it once, after the entity has its components::Badge and components::Animation and before the first setVisible().

Parameters
componentRegistryThe registry holding the components. It is captured by the sample handler and must outlive the entity.
entityIdentifierThe badge entity.
Exceptions
ecs::EntityComponentNotFoundExceptionWhen the entity has no components::Animation.

Definition at line 95 of file badge.cpp.

Here is the call graph for this function:

◆ needsLabel()

bool guillaume::systems::Badge::needsLabel ( const ecs::ComponentRegistry & componentRegistry,
const ecs::Entity::Identifier & entityIdentifier )
static

Whether the badge should have a label child.

entities::Badge uses it to decide whether to create the label entity.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe badge entity.
Returns
False for the Dot variant or an empty label, true otherwise.

Definition at line 129 of file badge.cpp.

Here is the call graph for this function:

◆ setVisible()

void guillaume::systems::Badge::setVisible ( ecs::ComponentRegistry & componentRegistry,
const ecs::Entity::Identifier & entityIdentifier,
bool visible )
static

Show or hide the badge with a fade.

Records the target visibility and the opacity the fade starts from, then plays the badge's components::Animation. Starting from the current opacity keeps a fade that is reversed half-way continuous. Does nothing when the visibility is already the requested one. Call install() first: it is what makes the animation change the opacity.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe badge entity.
visibleTrue to fade in, false to fade out.

Definition at line 138 of file badge.cpp.

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

◆ sizeOf()

float guillaume::systems::Badge::sizeOf ( const ecs::ComponentRegistry & componentRegistry,
const ecs::Entity::Identifier & entityIdentifier )
static

Get the height of a badge, in dp.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe badge entity.
Returns
The size override of components::Badge when one is set, otherwise the size of the variant: 6 (dot), 16 (small) or 20 (large).

Definition at line 109 of file badge.cpp.

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

◆ update()

void guillaume::systems::Badge::update ( const ecs::Entity::Identifier & entityIdentifier)
overridevirtual

Run apply() on one badge; called by the frame loop.

Logs a warning and does nothing when the entity has no components::Badge.

Parameters
entityIdentifierThe badge entity.

Implements guillaume::ecs::System.

Definition at line 210 of file badge.cpp.

Here is the call graph for this function:

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