guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
dialog.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#include <vector>
28
29#include "guillaume/ecs/component.hpp"
30#include "guillaume/ecs/entity.hpp"
31
33{
34
53 class Dialog: public ecs::Component
54 {
55 public:
65 enum class Variant { Alert, Simple, Confirmation, FullScreen };
66
71 struct Action {
72 std::string label;
73 std::function<void(void)> onPress;
75 };
76
78 static constexpr float Width = 320.0f;
79
81 static constexpr float FullScreenHeight = 640.0f;
82
83 private:
84 Variant _variant { Variant::Alert };
85 std::string _title {};
86 std::string _message {};
87 std::vector<Action> _actions {};
88 std::string _icon {};
89 ecs::Entity::Identifier _iconEntity {
91 };
92
93 ecs::Entity::Identifier _titleEntity {
95 };
96
97 ecs::Entity::Identifier _messageEntity {
99 };
100
101 std::vector<ecs::Entity::Identifier>
102 _actionEntities {};
103 ecs::Entity::Identifier _actionRow {
105 };
106
107 ecs::Entity::Identifier _backdrop {
109 };
110
111 public:
115 Dialog(void) = default;
116
120 ~Dialog(void) = default;
121
126 Variant getVariant(void) const noexcept;
127
135 Dialog &setVariant(Variant variant);
136
141 const std::string &getTitle(void) const noexcept;
142
151 Dialog &setTitle(const std::string &title);
152
157 const std::string &getMessage(void) const noexcept;
158
167 Dialog &setMessage(const std::string &message);
168
173 const std::vector<Action> &getActions(void) const noexcept;
174
184 Dialog &setActions(std::vector<Action> actions);
185
191 const std::string &getIcon(void) const noexcept;
192
201 Dialog &setIcon(const std::string &icon);
202
209 std::string getEffectiveIcon(void) const;
210
216 ecs::Entity::Identifier getIconEntity(void) const noexcept;
217
226
232 ecs::Entity::Identifier getTitleEntity(void) const noexcept;
233
242
248 ecs::Entity::Identifier getMessageEntity(void) const noexcept;
249
258
263 const std::vector<ecs::Entity::Identifier> &
264 getActionEntities(void) const noexcept;
265
274 const std::vector<ecs::Entity::Identifier> &identifiers);
275
282 ecs::Entity::Identifier getActionRow(void) const noexcept;
283
292
298 ecs::Entity::Identifier getBackdrop(void) const noexcept;
299
308 };
309
310} // 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
static constexpr float FullScreenHeight
Height of a full-screen dialog, in dp.
Definition dialog.hpp:81
~Dialog(void)=default
Default destructor.
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
static constexpr float Width
Width of the dialog panel, in dp.
Definition dialog.hpp:78
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
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.
@ Alert
Live announcement (snackbar).
One action of the dialog, drawn as a text button in the action row.
Definition dialog.hpp:71
std::string label
Text of the button.
Definition dialog.hpp:72
std::function< void(void)> onPress
Definition dialog.hpp:73