Nui
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
dialog.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <functional>
8
10{
15 {
16 public:
17 enum class Button
18 {
19 Ok,
20 Cancel,
21 Yes,
22 No,
23 };
25 {
26 Ok,
28 YesNo,
29 None
30 };
31
33 {
34 std::optional<std::string> className{std::nullopt};
35 std::string title{};
36 std::string body{};
37 std::string buttonClassName{};
39 std::function<void(Button)> onButtonClicked = [](Button) {};
40 };
41
47 explicit DialogController(ConstructionArgs&& args);
48
52 void showModal();
53
57 void show();
58
62 void hide();
63
67 bool isOpen() const;
68
72 void setClassName(std::string const& className);
73
77 void setButtonClassName(std::string const& className);
78
82 void setTitle(std::string const& title);
83
87 void setBody(std::string const& body);
88
93
97 void setOnButtonClicked(std::function<void(Button)> const& onButtonClicked);
98
104 friend Nui::ElementRenderer Dialog(DialogController& controller);
105
106 private:
107 bool isOpen_;
108 std::weak_ptr<Dom::Element> element_;
112 Observed<std::string> buttonClassName_;
113 Observed<ButtonConfiguration> buttonConfiguration_;
114 std::function<void(Button)> onButtonClicked_;
115 };
116}
Examplary dialog class for the most simple kinds of dialogs.
Definition dialog.hpp:15
friend Nui::ElementRenderer Dialog(DialogController &controller)
Creates a dialog element with the specified controller.
Definition dialog.cpp:90
void setClassName(std::string const &className)
Sets the class name of the dialog.
Definition dialog.cpp:60
void setTitle(std::string const &title)
Sets the title of the dialog.
Definition dialog.cpp:70
void setOnButtonClicked(std::function< void(Button)> const &onButtonClicked)
Sets the callback that is called when a button is clicked.
Definition dialog.cpp:85
void setButtonConfiguration(ButtonConfiguration buttons)
Sets the button configuration of the dialog.
Definition dialog.cpp:80
void hide()
Hides the dialog.
Definition dialog.cpp:48
void setBody(std::string const &body)
Sets the body of the dialog.
Definition dialog.cpp:75
void showModal()
Shows the dialog as a modal dialog (blocks the UI).
Definition dialog.cpp:34
bool isOpen() const
Returns true if the dialog is open.
Definition dialog.cpp:55
void show()
Shows the dialog as a non-modal dialog (does not block the UI).
Definition dialog.cpp:41
void setButtonClassName(std::string const &className)
Sets the class name of the dialog buttons.
Definition dialog.cpp:65
Button
Definition dialog.hpp:18
ButtonConfiguration
Definition dialog.hpp:25
Definition observed_value.hpp:1283
Definition dialog.hpp:10
std::function< std::shared_ptr< Dom::Element >(Dom::Element &, Renderer const &)> ElementRenderer
Definition element_renderer.hpp:11
std::optional< std::string > className
Definition dialog.hpp:34
std::string title
Definition dialog.hpp:35
ButtonConfiguration buttonConfiguration
Definition dialog.hpp:38
std::string body
Definition dialog.hpp:36
std::function< void(Button)> onButtonClicked
Definition dialog.hpp:39
std::string buttonClassName
Definition dialog.hpp:37