guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
snackbar.cpp
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#include "guillaume/components/snackbar.hpp"
24
25#include <stdexcept>
26#include <utility>
27
29{
31 {
32 return _variant;
33 }
34
36 {
37 if (_variant != variant) {
38 _variant = variant;
39 setHasChanged(true);
40 }
41 return *this;
42 }
43
44 const std::string &Snackbar::getMessage(void) const noexcept
45 {
46 return _message;
47 }
48
49 Snackbar &Snackbar::setMessage(const std::string &message)
50 {
51 if (_message != message) {
52 _message = message;
53 setHasChanged(true);
54 }
55 return *this;
56 }
57
58 const std::string &Snackbar::getAction(void) const noexcept
59 {
60 return _action;
61 }
62
63 Snackbar &Snackbar::setAction(const std::string &action)
64 {
65 if (_action != action) {
66 _action = action;
67 setHasChanged(true);
68 }
69 return *this;
70 }
71
73 {
74 return _messageEntity;
75 }
76
78 {
79 if (_messageEntity != identifier) {
80 _messageEntity = identifier;
81 setHasChanged(true);
82 }
83 return *this;
84 }
85
87 {
88 return _actionEntity;
89 }
90
92 {
93 if (_actionEntity != identifier) {
94 _actionEntity = identifier;
95 setHasChanged(true);
96 }
97 return *this;
98 }
99
100 bool Snackbar::isVisible(void) const noexcept
101 {
102 return _visible;
103 }
104
106 {
107 if (_visible != visible) {
108 _visible = visible;
109 setHasChanged(true);
110 }
111 return *this;
112 }
113
114 float Snackbar::getDuration(void) const noexcept
115 {
116 return _duration;
117 }
118
120 {
121 if (seconds < 0.0f) {
122 throw std::invalid_argument("Snackbar duration must be >= 0");
123 }
124 if (_duration != seconds) {
125 _duration = seconds;
126 setHasChanged(true);
127 }
128 return *this;
129 }
130
131 const Snackbar::Handler &Snackbar::getOnDismiss(void) const noexcept
132 {
133 return _onDismiss;
134 }
135
137 {
138 _onDismiss = std::move(handler);
139 return *this;
140 }
141
142 const Snackbar::Handler &Snackbar::getOnAction(void) const noexcept
143 {
144 return _onAction;
145 }
146
148 {
149 _onAction = std::move(handler);
150 return *this;
151 }
152} // namespace guillaume::components
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
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 & 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
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
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
State. Every class here is plain data attached to an entity.