TGUI  0.10-beta
MessageBox.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_MESSAGE_BOX_HPP
27#define TGUI_MESSAGE_BOX_HPP
28
29
30#include <TGUI/Widgets/Label.hpp>
31#include <TGUI/Widgets/Button.hpp>
32#include <TGUI/Widgets/ChildWindow.hpp>
33#include <TGUI/Renderers/MessageBoxRenderer.hpp>
34
35#undef MessageBox // windows.h defines MessageBox when NOMB isn't defined before including windows.h
36
38
39namespace tgui
40{
44 class TGUI_API MessageBox : public ChildWindow
45 {
46 public:
47
48 typedef std::shared_ptr<MessageBox> Ptr;
49 typedef std::shared_ptr<const MessageBox> ConstPtr;
50
51
59 MessageBox(const char* typeName = "MessageBox", bool initRenderer = true);
60
61
71 static MessageBox::Ptr create(String title = "", String text = "", std::vector<String> buttons = {});
72
73
77 MessageBox(const MessageBox& copy);
78
79
84
85
89 MessageBox& operator= (const MessageBox& right);
90
91
95 MessageBox& operator= (MessageBox&& right);
96
97
107
108
114 const MessageBoxRenderer* getSharedRenderer() const;
115
122 const MessageBoxRenderer* getRenderer() const;
123
124
134 void setText(const String& text);
135
136
143 const String& getText() const;
144
145
155 void addButton(const String& buttonCaption);
156
157
164 std::vector<String> getButtons() const;
165
166
168 protected:
169
171 // Makes sure all widgets lie within the window and places them on the correct position.
173 void rearrange();
174
175
185 Signal& getSignal(String signalName) override;
186
187
194 void rendererChanged(const String& property) override;
195
196
200 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
201
202
206 void updateTextSize() override;
207
208
210 // Makes a copy of the widget
212 Widget::Ptr clone() const override;
213
214
216 private:
217
219 // Figure out which widget is the label and which are the buttons after copying or loading
221 void identifyLabelAndButtons();
222
223
225 // Passes our onButtonPress signal handler to the onPress signal of a button
227 void connectButtonPressSignal(std::size_t buttonIndex);
228
229
231 public:
232
233 SignalString onButtonPress = {"ButtonPressed"};
234
235
237 protected:
238
239 String m_loadedThemeFile;
240 String m_buttonClassName;
241
242 std::vector<Button::Ptr> m_buttons;
243
244 Label::Ptr m_label = Label::create();
245 };
246
248}
249
251
252#endif // TGUI_MESSAGE_BOX_HPP
Child window widget.
Definition: ChildWindow.hpp:44
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition: Label.hpp:47
static Label::Ptr create(String text="")
Creates a new label widget.
Definition: MessageBoxRenderer.hpp:37
Message box widget.
Definition: MessageBox.hpp:45
std::vector< String > getButtons() const
Returns the caption of the buttons.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
static MessageBox::Ptr create(String title="", String text="", std::vector< String > buttons={})
Creates a new message box widget.
MessageBox(MessageBox &&copy)
Move constructor.
MessageBox(const MessageBox &copy)
Copy constructor.
void setText(const String &text)
Changes the text of the message box.
const String & getText() const
Returns the text of the message box.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
MessageBoxRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
MessageBoxRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::shared_ptr< MessageBox > Ptr
Shared widget pointer.
Definition: MessageBox.hpp:48
void addButton(const String &buttonCaption)
Adds a button to the message box.
std::shared_ptr< const MessageBox > ConstPtr
Shared constant widget pointer.
Definition: MessageBox.hpp:49
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
static MessageBox::Ptr copy(MessageBox::ConstPtr messageBox)
Makes a copy of another message box.
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Wrapper class to store strings.
Definition: String.hpp:79
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36