1/*
2 src/messagedialog.cpp -- Simple "OK" or "Yes/No"-style modal dialogs
3
4 NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>.
5 The widget drawing code is based on the NanoVG demo application
6 by Mikko Mononen.
7
8 All rights reserved. Use of this source code is governed by a
9 BSD-style license that can be found in the LICENSE.txt file.
10*/
11
12#include <nanogui/messagedialog.h>
13#include <nanogui/layout.h>
14#include <nanogui/button.h>
15#include <nanogui/label.h>
16
17NAMESPACE_BEGIN(nanogui)
18
19MessageDialog::MessageDialog(Widget *parent, Type type, const std::string &title,
20 const std::string &message,
21 const std::string &buttonText,
22 const std::string &altButtonText, bool altButton) : Window(parent, title) {
23 setLayout(new BoxLayout(Orientation::Vertical,
24 Alignment::Middle, 10, 10));
25 setModal(true);
26
27 Widget *panel1 = new Widget(this);
28 panel1->setLayout(new BoxLayout(Orientation::Horizontal,
29 Alignment::Middle, 10, 15));
30 int icon = 0;
31 switch (type) {
32 case Type::Information: icon = mTheme->mMessageInformationIcon; break;
33 case Type::Question: icon = mTheme->mMessageQuestionIcon; break;
34 case Type::Warning: icon = mTheme->mMessageWarningIcon; break;
35 }
36 Label *iconLabel = new Label(panel1, std::string(utf8(icon).data()), "icons");
37 iconLabel->setFontSize(50);
38 mMessageLabel = new Label(panel1, message);
39 mMessageLabel->setFixedWidth(200);
40 Widget *panel2 = new Widget(this);
41 panel2->setLayout(new BoxLayout(Orientation::Horizontal,
42 Alignment::Middle, 0, 15));
43
44 if (altButton) {
45 Button *button = new Button(panel2, altButtonText, mTheme->mMessageAltButtonIcon);
46 button->setCallback([&] { if (mCallback) mCallback(1); dispose(); });
47 }
48 Button *button = new Button(panel2, buttonText, mTheme->mMessagePrimaryButtonIcon);
49 button->setCallback([&] { if (mCallback) mCallback(0); dispose(); });
50 center();
51 requestFocus();
52}
53
54NAMESPACE_END(nanogui)
55