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 <utility>
26#include <cstddef>
27#include <functional>
28#include <memory>
29#include <string>
30#include <vector>
31
32#include <utility/graphic/color.hpp>
33#include <utility/graphic/pose.hpp>
34
35#include "guillaume/ecs/component_registry.hpp"
36#include "guillaume/ecs/entity_builder.hpp"
37
38#include "guillaume/components/accessibility.hpp"
39#include "guillaume/components/dialog.hpp"
40#include "guillaume/components/elevation.hpp"
41#include "guillaume/components/overlay.hpp"
42
43#include "guillaume/entities/backdrop.hpp"
44#include "guillaume/entities/button.hpp"
45#include "guillaume/entities/icon.hpp"
46#include "guillaume/entities/view.hpp"
47#include "guillaume/entities/builder_base.hpp"
48#include "guillaume/entities/surface.hpp"
49#include "guillaume/entities/text.hpp"
50
51namespace guillaume::entities
52{
53
109 class Dialog:
110 public SurfaceBase<components::Overlay, components::Elevation,
111 components::Accessibility, components::Dialog>
112 {
113 public:
116
120
125 class Builder: public EntityBuilderBase<Dialog>
126 {
127 private:
128 SurfaceConfig _config;
129 Variant _variant { Variant::Alert };
130 std::string _title {};
131 std::string _message {};
132 std::vector<Action> _actions {};
133 std::string _icon {};
134 std::function<void(void)> _onDismiss {};
135
136 public:
144 Builder(ecs::ComponentRegistry &componentRegistry,
145 ecs::EntityRegistry &entityRegistry);
146
152 std::shared_ptr<Dialog> buildEntity(void) override;
153
159 void reset(void) override;
160
167 Builder &withPose(const utility::graphic::PoseF &pose);
168
174 Builder &withVariant(Variant variant);
175
182 Builder &withTitle(const std::string &title);
183
190 Builder &withMessage(const std::string &message);
191
201 Builder &addAction(const std::string &label,
202 std::function<void(void)> onPress = {});
203
211 Builder &withIcon(const std::string &iconGlyph);
212
219 Builder &withOnDismiss(std::function<void(void)> onDismiss);
220
237 std::shared_ptr<Dialog>
238 makeDialog(std::shared_ptr<ecs::Entity> parent, Variant variant,
239 const std::string &title, const std::string &message,
240 const std::vector<std::string> &actions = {});
241 };
242
263 Dialog(ecs::ComponentRegistry &registry, const SurfaceConfig &config,
264 Variant variant, const std::string &title,
265 const std::string &message, const std::vector<Action> &actions,
266 const std::string &icon,
267 std::function<void(void)> onDismiss = {});
268
282 template<typename... Arguments>
283 static std::shared_ptr<Dialog> create(Arguments &&...arguments)
284 {
285 std::shared_ptr<Dialog> entity(
286 new Dialog(std::forward<Arguments>(arguments)...));
287 entity->build();
288 return entity;
289 }
290
294 ~Dialog(void) override = default;
295
305 Dialog &setVariant(Variant variant);
306
311 Variant getVariant(void) const;
312
322 Dialog &setTitle(const std::string &title);
323
333 Dialog &setMessage(const std::string &message);
334
342 Dialog &show(void);
343
351 Dialog &hide(void);
352
358 bool isVisible(void) const;
359
364 Dialog &open(void);
365
370 Dialog &close(void);
371
376 bool isOpen(void) const;
377
385 Dialog &dismiss(void);
386
397 Dialog &setOnDismiss(std::function<void(void)> onDismiss);
398
404 std::size_t getActionCount(void) const;
405
412 ecs::Entity::Identifier getActionIdentifier(std::size_t index) const;
413
421
429
436
437 private:
445 void buildContent(void);
446
451 void buildActionRow(void);
452
453 private:
465 Dialog(ecs::ComponentRegistry &registry, const SurfaceConfig &config,
466 Variant variant, const std::string &title,
467 const std::string &message,
468 const std::vector<std::string> &actions);
469
476 void build(void);
477 };
478
479} // namespace guillaume::entities
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
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
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Definition dialog.cpp:67
Builder & withTitle(const std::string &title)
Set the title, shown above the message.
Definition dialog.cpp:116
Builder & withPose(const utility::graphic::PoseF &pose)
Set the pose the dialog is created with.
Definition dialog.cpp:104
Builder & addAction(const std::string &label, std::function< void(void)> onPress={})
Append an action, shown as a text button at the end of the action row.
Definition dialog.cpp:129
void reset(void) override
Restore the defaults: Alert variant, no title, no message, no action, no icon, no dismiss handler,...
Definition dialog.cpp:82
std::shared_ptr< Dialog > makeDialog(std::shared_ptr< ecs::Entity > parent, Variant variant, const std::string &title, const std::string &message, const std::vector< std::string > &actions={})
Build a dialog, register it under parent and reset the builder.
Definition dialog.cpp:150
Builder & withVariant(Variant variant)
Set the dialog variant.
Definition dialog.cpp:110
Builder & withMessage(const std::string &message)
Set the message, shown under the title.
Definition dialog.cpp:122
std::shared_ptr< Dialog > buildEntity(void) override
Build a dialog and its children from the current configuration, without registering it or setting its...
Definition dialog.cpp:74
Builder & withIcon(const std::string &iconGlyph)
Set the icon shown above the title.
Definition dialog.cpp:136
Builder & withOnDismiss(std::function< void(void)> onDismiss)
Set the handler called when the dialog is dismissed (see Dialog::setOnDismiss()).
Definition dialog.cpp:143
Dialog & close(void)
Hide the dialog; same as hide().
Definition dialog.cpp:258
Dialog & show(void)
Show the dialog and, except for the FullScreen variant, its backdrop.
Definition dialog.cpp:234
bool isOpen(void) const
Check whether the dialog is shown; same as isVisible().
Definition dialog.cpp:263
ecs::Entity::Identifier getIconIdentifier(void) const
Get the identifier of the icon shown above the title.
Definition dialog.cpp:315
Dialog(ecs::ComponentRegistry &registry, const SurfaceConfig &config, Variant variant, const std::string &title, const std::string &message, const std::vector< Action > &actions, const std::string &icon, std::function< void(void)> onDismiss={})
Construct a dialog with pressable actions and an icon.
Definition dialog.cpp:173
Dialog & open(void)
Show the dialog; same as show().
Definition dialog.cpp:253
bool isVisible(void) const
Check whether the dialog is shown.
Definition dialog.cpp:246
static std::shared_ptr< Dialog > create(Arguments &&...arguments)
Create a dialog and its children, without registering it in an entity registry.
Definition dialog.hpp:283
Dialog & setVariant(Variant variant)
Change the dialog variant.
Definition dialog.cpp:196
Variant getVariant(void) const
Get the dialog variant.
Definition dialog.cpp:207
Dialog & dismiss(void)
Dismiss the dialog as the user would: hide it, then call the dismiss handler.
Definition dialog.cpp:268
ecs::Entity::Identifier getBackdropIdentifier(void) const
Get the identifier of the backdrop drawn behind the panel.
Definition dialog.cpp:308
~Dialog(void) override=default
Default destructor.
components::Dialog::Action Action
Definition dialog.hpp:119
ecs::Entity::Identifier getActionRowIdentifier(void) const
Get the identifier of the row that holds the action buttons.
Definition dialog.cpp:301
Dialog & setMessage(const std::string &message)
Change the message text.
Definition dialog.cpp:224
ecs::Entity::Identifier getActionIdentifier(std::size_t index) const
Get the identifier of an action button.
Definition dialog.cpp:290
Dialog & setOnDismiss(std::function< void(void)> onDismiss)
Set the handler called when the dialog is dismissed (Paper onDismiss).
Definition dialog.cpp:274
Dialog & setTitle(const std::string &title)
Change the title text.
Definition dialog.cpp:214
Dialog & hide(void)
Hide the dialog and its backdrop.
Definition dialog.cpp:240
std::size_t getActionCount(void) const
Get the number of action buttons.
Definition dialog.cpp:282
components::Dialog::Variant Variant
Look of the dialog: Alert, Simple, Confirmation or FullScreen.
Definition dialog.hpp:115
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
One action of the dialog, drawn as a text button in the action row.
Definition dialog.hpp:71
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...
Definition surface.hpp:71