Nui
dialog.hpp
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include <functional>
9 
10 namespace Nui::Components
11 {
16  {
17  public:
18  enum class Button
19  {
20  Ok,
21  Cancel,
22  Yes,
23  No,
24  };
26  {
27  Ok,
28  OkCancel,
29  YesNo,
30  None
31  };
32 
34  {
35  std::optional<std::string> className{std::nullopt};
36  std::string title{""};
37  std::string body{""};
38  std::string buttonClassName{""};
40  std::function<void(Button)> onButtonClicked = [](Button) {};
41  };
42 
48  DialogController(ConstructionArgs&& args);
49 
53  void showModal();
54 
58  void show();
59 
63  void hide();
64 
68  bool isOpen() const;
69 
73  void setClassName(std::string const& className);
74 
78  void setButtonClassName(std::string const& className);
79 
83  void setTitle(std::string const& title);
84 
88  void setBody(std::string const& body);
89 
94 
98  void setOnButtonClicked(std::function<void(Button)> const& onButtonClicked);
99 
105  friend Nui::ElementRenderer Dialog(DialogController& controller);
106 
107  private:
108  bool isOpen_;
109  std::weak_ptr<Dom::Element> element_;
111  Observed<std::string> title_;
112  Observed<std::string> body_;
113  Observed<std::string> buttonClassName_;
114  Observed<ButtonConfiguration> buttonConfiguration_;
115  std::function<void(Button)> onButtonClicked_;
116  };
117 }
Examplary dialog class for the most simple kinds of dialogs.
Definition: dialog.hpp:16
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
DialogController(ConstructionArgs &&args)
Constructs a new DialogController.
Definition: dialog.cpp:23
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:19
ButtonConfiguration
Definition: dialog.hpp:26
Definition: observed_value.hpp:1202
Definition: dialog.hpp:11
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:35
std::string title
Definition: dialog.hpp:36
ButtonConfiguration buttonConfiguration
Definition: dialog.hpp:39
std::string body
Definition: dialog.hpp:37
std::function< void(Button)> onButtonClicked
Definition: dialog.hpp:40
std::string buttonClassName
Definition: dialog.hpp:38