--- --- TGUI: include/TGUI/Widgets/MessageBox.hpp Source File
TGUI  1.x-dev
Loading...
Searching...
No Matches
MessageBox.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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#ifndef TGUI_MESSAGE_BOX_HPP
26#define TGUI_MESSAGE_BOX_HPP
27
28#include <TGUI/Widgets/Label.hpp>
29#include <TGUI/Widgets/Button.hpp>
30#include <TGUI/Widgets/ChildWindow.hpp>
31#include <TGUI/Renderers/MessageBoxRenderer.hpp>
32
33#undef MessageBox // windows.h defines MessageBox when NOMB isn't defined before including windows.h
34
36
37TGUI_MODULE_EXPORT namespace tgui
38{
42 class TGUI_API MessageBox : public ChildWindow
43 {
44 public:
45
46 using Ptr = std::shared_ptr<MessageBox>;
47 using ConstPtr = std::shared_ptr<const MessageBox>;
48
49 static constexpr const char StaticWidgetType[] = "MessageBox";
50
54 using Alignment TGUI_DEPRECATED("Use tgui::HorizontalAlignment instead") = HorizontalAlignment; // TGUI_NEXT: Remove this alias
55
63 MessageBox(const char* typeName = StaticWidgetType, bool initRenderer = true);
64
74 TGUI_NODISCARD static MessageBox::Ptr create(const String& title = "", const String& text = "", const std::vector<String>& buttons = {});
75
79 MessageBox(const MessageBox& copy);
80
84 MessageBox(MessageBox&& copy) noexcept;
85
89 MessageBox& operator= (const MessageBox& right);
90
94 MessageBox& operator= (MessageBox&& right) noexcept;
95
104 TGUI_NODISCARD static MessageBox::Ptr copy(const MessageBox::ConstPtr& messageBox);
105
110 TGUI_NODISCARD MessageBoxRenderer* getSharedRenderer() override;
111 TGUI_NODISCARD const MessageBoxRenderer* getSharedRenderer() const override;
112
118 TGUI_NODISCARD MessageBoxRenderer* getRenderer() override;
119
131 void setSize(const Layout2d& size) override;
132 using Widget::setSize;
133
144 void setClientSize(const Layout2d& size) override;
145
155 void setText(const String& text);
156
163 TGUI_NODISCARD const String& getText() const;
164
174 void addButton(const String& buttonCaption);
175
193 void changeButtons(const std::vector<String>& buttonCaptions);
194
201 TGUI_NODISCARD std::vector<String> getButtons() const;
202
211
220
229
238
240 protected:
241
243 // Makes sure all widgets lie within the window and places them on the correct position.
245 void rearrange();
246
256 TGUI_NODISCARD Signal& getSignal(String signalName) override;
257
264 void rendererChanged(const String& property) override;
265
269 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
270
274 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
275
279 void updateTextSize() override;
280
282 // Makes a copy of the widget
284 TGUI_NODISCARD Widget::Ptr clone() const override;
285
287 private:
288
290 // Figure out which widget is the label and which are the buttons after copying or loading
292 void identifyLabelAndButtons();
293
295 // Passes our onButtonPress signal handler to the onPress signal of a button
297 void connectButtonPressSignal(std::size_t buttonIndex);
298
302 void addButtonImpl(const String& caption);
303
305 public:
306
307 SignalString onButtonPress = {"ButtonPressed"};
308
310 protected:
311
312 String m_loadedThemeFile;
313 String m_buttonClassName;
314 bool m_autoSize = true;
315 HorizontalAlignment m_labelAlignment = HorizontalAlignment::Left;
316 HorizontalAlignment m_buttonAlignment = HorizontalAlignment::Center;
317
318 std::vector<Button::Ptr> m_buttons;
319
320 Label::Ptr m_label = Label::create();
321 };
322
324}
325
327
328#endif // TGUI_MESSAGE_BOX_HPP
Child window widget.
Definition ChildWindow.hpp:45
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition Label.hpp:45
Class to store the position or size of a widget.
Definition Layout.hpp:328
Message box widget.
Definition MessageBox.hpp:43
void setLabelAlignment(HorizontalAlignment labelAlignment)
Changes where the label is located inside the window (left side, centered or right side)
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
static TGUI_NODISCARD MessageBox::Ptr copy(const MessageBox::ConstPtr &messageBox)
Makes a copy of another message box.
TGUI_NODISCARD const String & getText() const
Returns the text of the message box.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
TGUI_NODISCARD HorizontalAlignment getLabelAlignment() const
Returns where the label is located inside the window (left side, centered or right side)
std::shared_ptr< const MessageBox > ConstPtr
Shared constant widget pointer.
Definition MessageBox.hpp:47
MessageBox(const MessageBox &copy)
Copy constructor.
void setText(const String &text)
Changes the text of the message box.
TGUI_NODISCARD MessageBoxRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
static TGUI_NODISCARD MessageBox::Ptr create(const String &title="", const String &text="", const std::vector< String > &buttons={})
Creates a new message box widget.
TGUI_NODISCARD HorizontalAlignment getButtonAlignment() const
Returns where the buttons are located inside the window (left side, centered or right side)
TGUI_NODISCARD 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.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void setButtonAlignment(HorizontalAlignment buttonAlignment)
Changes where the buttons are located inside the window (left side, centered or right side)
MessageBox(MessageBox &&copy) noexcept
Move constructor.
std::shared_ptr< MessageBox > Ptr
Shared widget pointer.
Definition MessageBox.hpp:46
TGUI_NODISCARD MessageBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void addButton(const String &buttonCaption)
Adds a button to the message box.
void changeButtons(const std::vector< String > &buttonCaptions)
Adds, removes, or updates buttons from the message box.
void setSize(const Layout2d &size) override
Changes the size of the message box.
void setClientSize(const Layout2d &size) override
Changes the client size of the child window.
TGUI_NODISCARD std::vector< String > getButtons() const
Returns the caption of the buttons.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition MessageBoxRenderer.hpp:37
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:52