guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
snackbar.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <functional>
26#include <string>
27
28#include "guillaume/ecs/component.hpp"
29#include "guillaume/ecs/entity.hpp"
30
32{
33
54 {
55 public:
62 enum class Variant { SingleLine, MultiLine, WithAction };
63
66 using Handler = std::function<void(void)>;
67
69 static constexpr float DurationShort = 4.0f;
70
72 static constexpr float DurationMedium = 7.0f;
73
75 static constexpr float DurationLong = 10.0f;
76
77 private:
78 Variant _variant { Variant::SingleLine };
79 std::string _message {};
80 std::string _action {};
81 ecs::Entity::Identifier _messageEntity {
83 };
84
85 ecs::Entity::Identifier _actionEntity {
87 };
88
89 bool _visible { true };
90 float _duration { DurationMedium };
91 Handler _onDismiss {};
92 Handler _onAction {};
93
94 public:
99 Snackbar(void) = default;
100
104 ~Snackbar(void) = default;
105
110 Variant getVariant(void) const noexcept;
111
119 Snackbar &setVariant(Variant variant);
120
125 const std::string &getMessage(void) const noexcept;
126
135 Snackbar &setMessage(const std::string &message);
136
141 const std::string &getAction(void) const noexcept;
142
152 Snackbar &setAction(const std::string &action);
153
159 ecs::Entity::Identifier getMessageEntity(void) const noexcept;
160
169
175 ecs::Entity::Identifier getActionEntity(void) const noexcept;
176
185
190 bool isVisible(void) const noexcept;
191
202 Snackbar &setVisible(bool visible);
203
209 float getDuration(void) const noexcept;
210
220 Snackbar &setDuration(float seconds);
221
226 const Handler &getOnDismiss(void) const noexcept;
227
238 Snackbar &setOnDismiss(Handler handler);
239
244 const Handler &getOnAction(void) const noexcept;
245
254 Snackbar &setOnAction(Handler handler);
255 };
256
257} // namespace guillaume::components
static constexpr float DurationLong
Long display time, in seconds.
Definition snackbar.hpp:75
Snackbar & setMessage(const std::string &message)
Set the message shown in the bar.
Definition snackbar.cpp:49
Snackbar & setAction(const std::string &action)
Set the label of the action, such as "Undo".
Definition snackbar.cpp:63
Snackbar & setActionEntity(ecs::Entity::Identifier identifier)
Record the pressable child that draws the action label.
Definition snackbar.cpp:91
Snackbar & setDuration(float seconds)
Set how long the snackbar stays on screen once shown.
Definition snackbar.cpp:119
Variant getVariant(void) const noexcept
Get the kind of snackbar.
Definition snackbar.cpp:30
float getDuration(void) const noexcept
Get how long the snackbar stays on screen.
Definition snackbar.cpp:114
const Handler & getOnAction(void) const noexcept
Get the callback run when the action is pressed.
Definition snackbar.cpp:142
std::function< void(void)> Handler
Definition snackbar.hpp:66
static constexpr float DurationMedium
Medium display time, in seconds. This is the default.
Definition snackbar.hpp:72
Snackbar & setMessageEntity(ecs::Entity::Identifier identifier)
Record the child that draws the message.
Definition snackbar.cpp:77
Snackbar & setOnDismiss(Handler handler)
Set the callback run when the snackbar is dismissed.
Definition snackbar.cpp:136
Snackbar & setOnAction(Handler handler)
Set the callback run when the action is pressed.
Definition snackbar.cpp:147
ecs::Entity::Identifier getActionEntity(void) const noexcept
Get the pressable child that draws the action label.
Definition snackbar.cpp:86
Snackbar(void)=default
Create the configuration of a visible, empty single-line snackbar that lasts DurationMedium.
bool isVisible(void) const noexcept
Tell whether the snackbar is shown.
Definition snackbar.cpp:100
Snackbar & setVariant(Variant variant)
Set the kind of snackbar, which decides its height.
Definition snackbar.cpp:35
const Handler & getOnDismiss(void) const noexcept
Get the callback run when the snackbar is dismissed.
Definition snackbar.cpp:131
~Snackbar(void)=default
Default destructor.
static constexpr float DurationShort
Short display time, in seconds.
Definition snackbar.hpp:69
Snackbar & setVisible(bool visible)
Record whether the snackbar is shown.
Definition snackbar.cpp:105
ecs::Entity::Identifier getMessageEntity(void) const noexcept
Get the child that draws the message.
Definition snackbar.cpp:72
const std::string & getAction(void) const noexcept
Get the label of the action.
Definition snackbar.cpp:58
const std::string & getMessage(void) const noexcept
Get the message shown in the bar.
Definition snackbar.cpp:44
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
State. Every class here is plain data attached to an entity.