guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
dialog.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/dialog.hpp"
24
25#include <algorithm>
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 &Dialog::getTitle(void) const noexcept
45 {
46 return _title;
47 }
48
49 Dialog &Dialog::setTitle(const std::string &title)
50 {
51 if (_title != title) {
52 _title = title;
53 setHasChanged(true);
54 }
55 return *this;
56 }
57
58 const std::string &Dialog::getMessage(void) const noexcept
59 {
60 return _message;
61 }
62
63 Dialog &Dialog::setMessage(const std::string &message)
64 {
65 if (_message != message) {
66 _message = message;
67 setHasChanged(true);
68 }
69 return *this;
70 }
71
72 const std::vector<Dialog::Action> &Dialog::getActions(void) const noexcept
73 {
74 return _actions;
75 }
76
77 Dialog &Dialog::setActions(std::vector<Action> actions)
78 {
79 const bool same = std::equal(
80 _actions.begin(), _actions.end(), actions.begin(), actions.end(),
81 [](const Action &left, const Action &right) {
82 return left.label == right.label;
83 });
84
85 _actions = std::move(actions);
86 if (!same) {
87 setHasChanged(true);
88 }
89 return *this;
90 }
91
92 const std::string &Dialog::getIcon(void) const noexcept
93 {
94 return _icon;
95 }
96
97 Dialog &Dialog::setIcon(const std::string &icon)
98 {
99 if (_icon != icon) {
100 _icon = icon;
101 setHasChanged(true);
102 }
103 return *this;
104 }
105
106 std::string Dialog::getEffectiveIcon(void) const
107 {
108 if (!_icon.empty()) {
109 return _icon;
110 }
111 return _variant == Variant::Confirmation ? std::string("info")
112 : std::string();
113 }
114
116 {
117 return _iconEntity;
118 }
119
121 {
122 if (_iconEntity != identifier) {
123 _iconEntity = identifier;
124 setHasChanged(true);
125 }
126 return *this;
127 }
128
130 {
131 return _titleEntity;
132 }
133
135 {
136 if (_titleEntity != identifier) {
137 _titleEntity = identifier;
138 setHasChanged(true);
139 }
140 return *this;
141 }
142
144 {
145 return _messageEntity;
146 }
147
149 {
150 if (_messageEntity != identifier) {
151 _messageEntity = identifier;
152 setHasChanged(true);
153 }
154 return *this;
155 }
156
157 const std::vector<ecs::Entity::Identifier> &
158 Dialog::getActionEntities(void) const noexcept
159 {
160 return _actionEntities;
161 }
162
164 const std::vector<ecs::Entity::Identifier> &identifiers)
165 {
166 if (_actionEntities != identifiers) {
167 _actionEntities = identifiers;
168 setHasChanged(true);
169 }
170 return *this;
171 }
172
174 {
175 return _actionRow;
176 }
177
179 {
180 if (_actionRow != identifier) {
181 _actionRow = identifier;
182 setHasChanged(true);
183 }
184 return *this;
185 }
186
188 {
189 return _backdrop;
190 }
191
193 {
194 if (_backdrop != identifier) {
195 _backdrop = identifier;
196 setHasChanged(true);
197 }
198 return *this;
199 }
200} // namespace guillaume::components
const std::string & getTitle(void) const noexcept
Get the title (headline) of the dialog.
Definition dialog.cpp:44
Dialog & setIcon(const std::string &icon)
Choose the icon shown above the title (the hero icon).
Definition dialog.cpp:97
Dialog & setMessageEntity(ecs::Entity::Identifier identifier)
Record the child that draws the message.
Definition dialog.cpp:148
Dialog(void)=default
Create the configuration of an empty alert dialog.
Dialog & setTitle(const std::string &title)
Set the title (headline) of the dialog.
Definition dialog.cpp:49
const std::vector< ecs::Entity::Identifier > & getActionEntities(void) const noexcept
Get the text buttons built for the actions.
Definition dialog.cpp:158
const std::string & getMessage(void) const noexcept
Get the message (supporting text) of the dialog.
Definition dialog.cpp:58
ecs::Entity::Identifier getMessageEntity(void) const noexcept
Get the child that draws the message.
Definition dialog.cpp:143
Dialog & setVariant(Variant variant)
Set the kind of dialog.
Definition dialog.cpp:35
const std::string & getIcon(void) const noexcept
Get the icon chosen for the top of the dialog.
Definition dialog.cpp:92
Dialog & setActionRow(ecs::Entity::Identifier identifier)
Record the row that holds the action buttons.
Definition dialog.cpp:178
Dialog & setMessage(const std::string &message)
Set the message (supporting text) of the dialog.
Definition dialog.cpp:63
Variant getVariant(void) const noexcept
Get the kind of dialog.
Definition dialog.cpp:30
Dialog & setActions(std::vector< Action > actions)
Replace the actions of the dialog.
Definition dialog.cpp:77
ecs::Entity::Identifier getBackdrop(void) const noexcept
Get the child that dims the content behind the dialog.
Definition dialog.cpp:187
ecs::Entity::Identifier getIconEntity(void) const noexcept
Get the child that draws the hero icon.
Definition dialog.cpp:115
const std::vector< Action > & getActions(void) const noexcept
Get the actions of the dialog.
Definition dialog.cpp:72
Dialog & setTitleEntity(ecs::Entity::Identifier identifier)
Record the child that draws the title.
Definition dialog.cpp:134
Dialog & setActionEntities(const std::vector< ecs::Entity::Identifier > &identifiers)
Record the text buttons built for the actions.
Definition dialog.cpp:163
Dialog & setIconEntity(ecs::Entity::Identifier identifier)
Record the child that draws the hero icon.
Definition dialog.cpp:120
Dialog & setBackdrop(ecs::Entity::Identifier identifier)
Record the child that dims the content behind the dialog.
Definition dialog.cpp:192
ecs::Entity::Identifier getTitleEntity(void) const noexcept
Get the child that draws the title.
Definition dialog.cpp:129
std::string getEffectiveIcon(void) const
Get the icon the dialog actually shows.
Definition dialog.cpp:106
ecs::Entity::Identifier getActionRow(void) const noexcept
Get the row that holds the action buttons, at the bottom of the panel.
Definition dialog.cpp:173
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.
One action of the dialog, drawn as a text button in the action row.
Definition dialog.hpp:71