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