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

State of a snackbar: a short message at the bottom of the screen, with an optional action, that goes away by itself. More...

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

Inheritance diagram for guillaume::components::Snackbar:
Collaboration diagram for guillaume::components::Snackbar:

Public Types

enum class  Variant { SingleLine , MultiLine , WithAction }
 Kind of snackbar. More...
using Handler = std::function<void(void)>

Public Member Functions

 Snackbar (void)=default
 Create the configuration of a visible, empty single-line snackbar that lasts DurationMedium.
 ~Snackbar (void)=default
 Default destructor.
Variant getVariant (void) const noexcept
 Get the kind of snackbar.
Snackbar & setVariant (Variant variant)
 Set the kind of snackbar, which decides its height.
const std::string & getMessage (void) const noexcept
 Get the message shown in the bar.
Snackbar & setMessage (const std::string &message)
 Set the message shown in the bar.
const std::string & getAction (void) const noexcept
 Get the label of the action.
Snackbar & setAction (const std::string &action)
 Set the label of the action, such as "Undo".
ecs::Entity::Identifier getMessageEntity (void) const noexcept
 Get the child that draws the message.
Snackbar & setMessageEntity (ecs::Entity::Identifier identifier)
 Record the child that draws the message.
ecs::Entity::Identifier getActionEntity (void) const noexcept
 Get the pressable child that draws the action label.
Snackbar & setActionEntity (ecs::Entity::Identifier identifier)
 Record the pressable child that draws the action label.
bool isVisible (void) const noexcept
 Tell whether the snackbar is shown.
Snackbar & setVisible (bool visible)
 Record whether the snackbar is shown.
float getDuration (void) const noexcept
 Get how long the snackbar stays on screen.
Snackbar & setDuration (float seconds)
 Set how long the snackbar stays on screen once shown.
const Handler & getOnDismiss (void) const noexcept
 Get the callback run when the snackbar is dismissed.
Snackbar & setOnDismiss (Handler handler)
 Set the callback run when the snackbar is dismissed.
const Handler & getOnAction (void) const noexcept
 Get the callback run when the action is pressed.
Snackbar & setOnAction (Handler handler)
 Set the callback run when the action is pressed.
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 DurationShort = 4.0f
 Short display time, in seconds.
static constexpr float DurationMedium = 7.0f
 Medium display time, in seconds. This is the default.
static constexpr float DurationLong = 10.0f
 Long display time, in seconds.

Detailed Description

State of a snackbar: a short message at the bottom of the screen, with an optional action, that goes away by itself.

The entities::Snackbar widget writes it: the message, the action label, the duration, the callbacks and the identifiers of the two children it builds. systems::Snackbar reads it every frame in the Layout phase and turns it into the bar's Layout, Color, Borders, Elevation, Overlay and Accessibility, and into the text and color of its message child and the color of its action child.

The visibility flag here is the one to set (through systems::Snackbar::show and systems::Snackbar::hide). The system copies it to the components::Overlay of the same entity, whose countdown then dismisses the bar after the duration. A hidden snackbar is drawn transparent.

See also
systems::Snackbar, components::Overlay, entities::Snackbar

Definition at line 53 of file snackbar.hpp.

Member Typedef Documentation

◆ Handler

using guillaume::components::Snackbar::Handler = std::function<void(void)>

Callback that takes no argument, used for dismissal and for the action.

Definition at line 66 of file snackbar.hpp.

Member Enumeration Documentation

◆ Variant

Kind of snackbar.

MultiLine makes the bar 68 dp high; SingleLine and WithAction are 48 dp high.

Definition at line 62 of file snackbar.hpp.

Member Function Documentation

◆ getAction()

const std::string & guillaume::components::Snackbar::getAction ( void ) const
noexcept

Get the label of the action.

Returns
The label; empty when the snackbar has no action.

Definition at line 58 of file snackbar.cpp.

◆ getActionEntity()

ecs::Entity::Identifier guillaume::components::Snackbar::getActionEntity ( void ) const
noexcept

Get the pressable child that draws the action label.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when the snackbar has no action.

Definition at line 86 of file snackbar.cpp.

Here is the caller graph for this function:

◆ getDuration()

float guillaume::components::Snackbar::getDuration ( void ) const
noexcept

Get how long the snackbar stays on screen.

Returns
The display time, in seconds; 0 means it stays until it is dismissed.

Definition at line 114 of file snackbar.cpp.

◆ getMessage()

const std::string & guillaume::components::Snackbar::getMessage ( void ) const
noexcept

Get the message shown in the bar.

Returns
The message; it is also the bar's accessible name.

Definition at line 44 of file snackbar.cpp.

◆ getMessageEntity()

ecs::Entity::Identifier guillaume::components::Snackbar::getMessageEntity ( void ) const
noexcept

Get the child that draws the message.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when it has not been built.

Definition at line 72 of file snackbar.cpp.

◆ getOnAction()

const Snackbar::Handler & guillaume::components::Snackbar::getOnAction ( void ) const
noexcept

Get the callback run when the action is pressed.

Returns
The callback; empty when none is set.

Definition at line 142 of file snackbar.cpp.

Here is the caller graph for this function:

◆ getOnDismiss()

const Snackbar::Handler & guillaume::components::Snackbar::getOnDismiss ( void ) const
noexcept

Get the callback run when the snackbar is dismissed.

Returns
The callback; empty when none is set.

Definition at line 131 of file snackbar.cpp.

◆ getVariant()

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

Get the kind of snackbar.

Returns
The variant, Variant::SingleLine by default.

Definition at line 30 of file snackbar.cpp.

◆ isVisible()

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

Tell whether the snackbar is shown.

Returns
True when shown, which is the default.

Definition at line 100 of file snackbar.cpp.

Here is the caller graph for this function:

◆ setAction()

Snackbar & guillaume::components::Snackbar::setAction ( const std::string & action)

Set the label of the action, such as "Undo".

The widget uses it when it builds the action child, and it is the accessible name of that child. Marks the component changed only when the label differs.

Parameters
actionThe new label.
Returns
This component, for chaining.

Definition at line 63 of file snackbar.cpp.

Here is the call graph for this function:

◆ setActionEntity()

Snackbar & guillaume::components::Snackbar::setActionEntity ( ecs::Entity::Identifier identifier)

Record the pressable child that draws the action label.

Marks the component changed only when the identifier differs.

Parameters
identifierThe child's identifier.
Returns
This component, for chaining.

Definition at line 91 of file snackbar.cpp.

Here is the call graph for this function:

◆ setDuration()

Snackbar & guillaume::components::Snackbar::setDuration ( float seconds)

Set how long the snackbar stays on screen once shown.

Marks the component changed only when the value differs.

Parameters
secondsThe display time, in seconds; 0 keeps the bar until it is dismissed.
Returns
This component, for chaining.
Exceptions
std::invalid_argumentIf seconds is negative.

Definition at line 119 of file snackbar.cpp.

Here is the call graph for this function:

◆ setMessage()

Snackbar & guillaume::components::Snackbar::setMessage ( const std::string & message)

Set the message shown in the bar.

systems::Snackbar copies it to the message child. Marks the component changed only when the text differs.

Parameters
messageThe new message.
Returns
This component, for chaining.

Definition at line 49 of file snackbar.cpp.

Here is the call graph for this function:

◆ setMessageEntity()

Snackbar & guillaume::components::Snackbar::setMessageEntity ( ecs::Entity::Identifier identifier)

Record the child that draws the message.

Marks the component changed only when the identifier differs.

Parameters
identifierThe child's identifier.
Returns
This component, for chaining.

Definition at line 77 of file snackbar.cpp.

Here is the call graph for this function:

◆ setOnAction()

Snackbar & guillaume::components::Snackbar::setOnAction ( Handler handler)

Set the callback run when the action is pressed.

The snackbar is dismissed right after the callback returns. Does not mark the component changed.

Parameters
handlerThe callback; an empty one removes it.
Returns
This component, for chaining.

Definition at line 147 of file snackbar.cpp.

Here is the call graph for this function:

◆ setOnDismiss()

Snackbar & guillaume::components::Snackbar::setOnDismiss ( Handler handler)

Set the callback run when the snackbar is dismissed.

It runs when the display time ends, on Escape, and after the action is pressed. It does not run when the snackbar is hidden with systems::Snackbar::hide. Does not mark the component changed.

Parameters
handlerThe callback; an empty one removes it.
Returns
This component, for chaining.

Definition at line 136 of file snackbar.cpp.

Here is the call graph for this function:

◆ setVariant()

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

Set the kind of snackbar, which decides its height.

Marks the component changed only when the variant differs.

Parameters
variantThe new variant.
Returns
This component, for chaining.

Definition at line 35 of file snackbar.cpp.

Here is the call graph for this function:

◆ setVisible()

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

Record whether the snackbar is shown.

This only stores the flag; the screen follows on the next pass of systems::Snackbar. Prefer systems::Snackbar::show and systems::Snackbar::hide, which also restyle the bar at once. Marks the component changed only when the flag differs.

Parameters
visibleTrue to show the snackbar.
Returns
This component, for chaining.

Definition at line 105 of file snackbar.cpp.

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

Member Data Documentation

◆ DurationLong

float guillaume::components::Snackbar::DurationLong = 10.0f
staticconstexpr

Long display time, in seconds.

Definition at line 75 of file snackbar.hpp.

◆ DurationMedium

float guillaume::components::Snackbar::DurationMedium = 7.0f
staticconstexpr

Medium display time, in seconds. This is the default.

Definition at line 72 of file snackbar.hpp.

◆ DurationShort

float guillaume::components::Snackbar::DurationShort = 4.0f
staticconstexpr

Short display time, in seconds.

Definition at line 69 of file snackbar.hpp.


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