TGUI  0.9-dev
MessageBox.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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
154 void setTextSize(unsigned int size) override;
155
156
166 void addButton(const String& buttonCaption);
167
168
175 std::vector<String> getButtons() const;
176
177
179 protected:
180
182 // Makes sure all widgets lie within the window and places them on the correct position.
184 void rearrange();
185
186
196 Signal& getSignal(String signalName) override;
197
198
205 void rendererChanged(const String& property) override;
206
207
211 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
212
213
217 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
218
219
221 // Makes a copy of the widget
223 Widget::Ptr clone() const override
224 {
225 return std::make_shared<MessageBox>(*this);
226 }
227
228
230 private:
231
233 // Figure out which widget is the label and which are the buttons after copying or loading
235 void identifyLabelAndButtons();
236
237
239 // Passes our onButtonPress signal handler to the onPress signal of a button
241 void connectButtonPressSignal(std::size_t buttonIndex);
242
243
245 public:
246
247 SignalString onButtonPress = {"ButtonPressed"};
248
249
251 protected:
252
253 String m_loadedThemeFile;
254 String m_buttonClassName;
255
256 std::vector<Button::Ptr> m_buttons;
257
258 Label::Ptr m_label = Label::create();
259 };
260
262}
263
265
266#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 setTextSize(unsigned int size) override
Changes the character size of the text.
static MessageBox::Ptr create(String title="", String text="", std::vector< String > buttons={})
Creates a new message box widget.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
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.
Definition: MessageBox.hpp:223
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