|
guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
|
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>


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. | |
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.
Definition at line 53 of file snackbar.hpp.
| 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.
|
strong |
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.
|
noexcept |
Get the label of the action.
Definition at line 58 of file snackbar.cpp.
|
noexcept |
Get the pressable child that draws the action label.
Definition at line 86 of file snackbar.cpp.

|
noexcept |
Get how long the snackbar stays on screen.
Definition at line 114 of file snackbar.cpp.
|
noexcept |
Get the message shown in the bar.
Definition at line 44 of file snackbar.cpp.
|
noexcept |
Get the child that draws the message.
Definition at line 72 of file snackbar.cpp.
|
noexcept |
Get the callback run when the action is pressed.
Definition at line 142 of file snackbar.cpp.

|
noexcept |
Get the callback run when the snackbar is dismissed.
Definition at line 131 of file snackbar.cpp.
|
noexcept |
Get the kind of snackbar.
Definition at line 30 of file snackbar.cpp.
|
noexcept |
Tell whether the snackbar is shown.
Definition at line 100 of file snackbar.cpp.

| 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.
| action | The new label. |
Definition at line 63 of file snackbar.cpp.

| 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.
| identifier | The child's identifier. |
Definition at line 91 of file snackbar.cpp.

| 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.
| seconds | The display time, in seconds; 0 keeps the bar until it is dismissed. |
| std::invalid_argument | If seconds is negative. |
Definition at line 119 of file snackbar.cpp.

| 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.
| message | The new message. |
Definition at line 49 of file snackbar.cpp.

| 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.
| identifier | The child's identifier. |
Definition at line 77 of file snackbar.cpp.

Set the callback run when the action is pressed.
The snackbar is dismissed right after the callback returns. Does not mark the component changed.
| handler | The callback; an empty one removes it. |
Definition at line 147 of file snackbar.cpp.

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.
| handler | The callback; an empty one removes it. |
Definition at line 136 of file snackbar.cpp.

Set the kind of snackbar, which decides its height.
Marks the component changed only when the variant differs.
| variant | The new variant. |
Definition at line 35 of file snackbar.cpp.

| 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.
| visible | True to show the snackbar. |
Definition at line 105 of file snackbar.cpp.


|
staticconstexpr |
Long display time, in seconds.
Definition at line 75 of file snackbar.hpp.
|
staticconstexpr |
Medium display time, in seconds. This is the default.
Definition at line 72 of file snackbar.hpp.
|
staticconstexpr |
Short display time, in seconds.
Definition at line 69 of file snackbar.hpp.