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

Styles a snackbar (a short message with an optional action that disappears on its own) and handles its dismissal. More...

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

Inheritance diagram for guillaume::systems::Snackbar:
Collaboration diagram for guillaume::systems::Snackbar:

Public Member Functions

 Snackbar (void)
 Create the system in the Layout phase.
 ~Snackbar (void) override=default
 Default destructor.
void update (const ecs::Entity::Identifier &entityIdentifier) override
 Run apply() on one snackbar; called by the frame loop.
Public Member Functions inherited from guillaume::ecs::SystemFiller< components::Snackbar >
 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)
 Give a snackbar its accessibility semantics and connect its dismissal.
static void installAction (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Make the action child a button that calls pressAction().
static void apply (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Style one snackbar and arrange its children.
static void show (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Show the snackbar and restart its auto-dismiss countdown.
static void hide (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Hide the snackbar without telling anyone.
static void dismiss (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Close the snackbar as the timeout, Escape or its action would.
static void pressAction (ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
 Activate the action as a press on it would.

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

Styles a snackbar (a short message with an optional action that disappears on its own) and handles its dismissal.

Runs in the Layout phase on every entity that has a components::Snackbar. It is registered after systems::Layout, so the message and action are already measured when it arranges them.

The visible flag of components::Snackbar is the source of truth: apply() copies it to the snackbar's components::Overlay. A hidden snackbar is not removed, it is painted transparent with no elevation.

This system does not count time. apply() gives the duration, in seconds, to the overlay as its auto-dismiss delay; systems::Overlay runs the countdown and handles Escape, and reports both through the overlay's dismiss handler, which install() points at dismiss().

systems::Snackbar::install(registry, snackbar);
systems::Snackbar::show(registry, snackbar); // countdown starts
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Give a snackbar its accessibility semantics and connect its dismissal.
Definition snackbar.cpp:76
static void show(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Show the snackbar and restart its auto-dismiss countdown.
Definition snackbar.cpp:118
See also
components::Snackbar, components::Overlay, entities::Snackbar, systems::Overlay

Definition at line 67 of file snackbar.hpp.

Constructor & Destructor Documentation

◆ Snackbar()

guillaume::systems::Snackbar::Snackbar ( void )

Create the system in the Layout phase.

Definition at line 71 of file snackbar.cpp.

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

Member Function Documentation

◆ apply()

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

Style one snackbar and arrange its children.

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

The bar is 48 dp high, or 68 dp for the MultiLine variant, with the message at one end and the action at the other. When the visible flag of the component and the one of the overlay differ, the overlay's elapsed time is reset to 0 before its flag is updated, which is what restarts the auto-dismiss countdown each time the snackbar is shown.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe snackbar entity.
Exceptions
ecs::EntityComponentNotFoundExceptionWhen the entity lacks one of the components listed in install().

Definition at line 174 of file snackbar.cpp.

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

◆ dismiss()

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

Close the snackbar as the timeout, Escape or its action would.

Hides the snackbar, then calls the dismiss callback of components::Snackbar when there is one. Does nothing when the snackbar is already hidden.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe snackbar entity.

Definition at line 134 of file snackbar.cpp.

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

◆ hide()

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

Hide the snackbar without telling anyone.

Clears the visible flag of components::Snackbar and calls apply(). The dismiss callback is not called: it is reserved for dismissals the application did not ask for.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe snackbar entity.

Definition at line 126 of file snackbar.cpp.

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

◆ install()

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

Give a snackbar its accessibility semantics and connect its dismissal.

Sets the role of its components::Accessibility to Alert with a polite live region, makes the dismiss handler of its components::Overlay call dismiss(), then calls installAction(). Call it once, after the entity has its components::Snackbar, Overlay, Elevation, Accessibility, Layout, Transform, Bound, Color and Borders.

Parameters
componentRegistryThe registry holding the components. It is captured by the handlers and must outlive the entity.
entityIdentifierThe snackbar entity.
Exceptions
ecs::EntityComponentNotFoundExceptionWhen the entity lacks components::Accessibility, Overlay or Snackbar.

Definition at line 76 of file snackbar.cpp.

Here is the call graph for this function:

◆ installAction()

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

Make the action child a button that calls pressAction().

Adds the interaction components to the action child recorded in components::Snackbar and gives it the action label as accessible name. Call it when the action child is created after install(). Does nothing when no action child is recorded.

Parameters
componentRegistryThe registry holding the components. It is captured by the press handler and must outlive the entity.
entityIdentifierThe snackbar entity.

Definition at line 96 of file snackbar.cpp.

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

◆ pressAction()

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

Activate the action as a press on it would.

Calls the action callback of components::Snackbar when there is one, then dismiss(), so the dismiss callback is called too. Does nothing when the snackbar is hidden.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe snackbar entity.

Definition at line 155 of file snackbar.cpp.

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

◆ show()

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

Show the snackbar and restart its auto-dismiss countdown.

Sets the visible flag of components::Snackbar and calls apply(). Showing a snackbar that is already shown does not restart the countdown.

Parameters
componentRegistryThe registry holding the components.
entityIdentifierThe snackbar entity.

Definition at line 118 of file snackbar.cpp.

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

◆ update()

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

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

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

Parameters
entityIdentifierThe snackbar entity.

Implements guillaume::ecs::System.

Definition at line 244 of file snackbar.cpp.

Here is the call graph for this function:

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