Class MessageDialog¶
- Defined in File messagedialog.h
Page Contents
Inheritance Relationships¶
Base Type¶
public nanogui::Window
(Class Window)
Class Documentation¶
-
class
MessageDialog
: public nanogui::Window¶ Simple “OK” or “Yes/No”-style modal dialogs.
Public Types
-
enum
Type
¶ Classification of the type of message this MessageDialog represents.
Values:
-
Information
¶ An information dialog. Uses Theme::mMessageInformationIcon.
-
Question
¶ An interogative dialog. Uses Theme::mMessageQuestionIcon.
-
Warning
¶ A warning dialog. Uses Theme::mMessageWarningIcon.
-
Public Functions
-
MessageDialog
(Widget *parent, Type type, const std::string &title = "Untitled", const std::string &message = "Message", const std::string &buttonText = "OK", const std::string &altButtonText = "Cancel", bool altButton = false)¶ Constructs a MessageDialog confined to the specified parent.
- Parameters
parent
: The parent, typically a Screen instance. It can also be e.g., a Window, but make sure that the parent is at least 250 pixels wide. If it is not, the positioning may be odd and moving the dialog will produce “snapping”.title
: The title of the window to use (default:"Untitled"
).type
: The type of message dialog (determines the icon displayed, see Type).message
: The dialog text you wish to display to the user (default:"Message"
). This is the text that mMessageLabel will get. It has a fixed width set to200
, meaning longer messages will automatically wrap to new lines.buttonText
: The button text for the confirmation button (default:"Ok"
). This button’s icon is defined by Theme::mMessagePrimaryButtonIcon.altButtonText
: The button text for the alternate button (default:"Cancel"
). This button’s icon is defined by Theme::mMessageAltButtonIcon.altButton
: Whether or not to include the alternate button (default:false
).
-
Label *
iconLabel
()¶ Returns mIconLabel.
-
const Label *
iconLabel
() const¶ Returns mIconLabel.
-
void
setIcon
(int icon)¶ Convenience method for setting mIconLabel. Must be a valid icon for the font used in mIconLabel. The default font face is
"icons"
, specified by Theme::mDefaultIconFont.The available icons for NanoGUI’s default icon font can be found in File entypo.h.
-
const Label *
messageLabel
() const¶ The Label that contains the
message
parameter to the constructor.
-
Button *
primaryButton
()¶ The primary button. See mPrimaryButton.
-
const Button *
primaryButton
() const¶ The primary button. See mPrimaryButton.
-
void
setPrimaryIcon
(int icon)¶ Convenience method, calls
mPrimaryButton->setIcon
.
-
Button *
alternateButton
()¶ The alternate button. See mAlternateButton. May be
nullptr
.
-
const Button *
alternateButton
() const¶ The alternate button. See mAlternateButton. May be
nulltpr
.
-
void
setAlternateIcon
(int icon)¶ Convenience method, calls
mAlternateButton->setIcon
.
-
std::function<void(int)>
callback
() const¶ The callback used for this MessageDialog. See mCallback.
-
void
setCallback
(const std::function<void(int)> &callback)¶ Sets the callback for this MessageDialog. See mCallback.
-
virtual void
setTheme
(Theme *theme)¶ Changes the theme for this MessageDialog.
Typically it is desirable to specify the
parent
in the constructor as a Screen instance. This will make the MessageDialog appear in the center of the screen. If you choose to customize the theme of say a specific window and want this MessageDialog to have this custom theme, make sure to call this method to update any colors / icons defined by this custom theme.auto dlg = MessageDialog(screen, MessageDialog::Type::Information); dlg->setTheme(mCustomTheme);// will update icons / colors accordingly
Protected Attributes
-
Type
mType
¶ Stored only to allow setTheme to correctly override mIconLabel.
-
Label *
mIconLabel
¶ An label with an icon as text, it’s font size is set to
50
. The initial value is determined by the MessageDialog::Type specified to the constructor. Call setIcon to change the icon.
-
Label *
mMessageLabel
¶ A Label that contains the
message
supplied to the constructor, with a fixed width of200
.
-
Button *
mPrimaryButton
¶ The primary button (caption:
buttonText
in constructor). A getter method primaryButton exists for you to change what you desire, such as the background color etc. However, be careful not to set the callback of this Button. Its callback is configured in the constructor to properly Window::dispose after a response. See documentation for MessageDialog::mCallback for how to know which button was clicked.
-
Button *
mAlternateButton
¶ The alternate button (caption:
altButtonText
in constructor). Only created whenaltButton=true
in the constructor. A getter method alternateButton exists for you to change what you desire, such as the background color etc. However, be careful not to set the callback of this Button. Its callback is configured in the constructor to properly Window::dispose after a response. See documentation for MessageDialog::mCallback for how to know which button was clicked.
-
std::function<void(int)>
mCallback
¶ The callback to execute when either the primary or alternate button are pressed. When constructed with
altButton=false
, only one button will be added (defined bybuttonText
). In this case, the callback will always be called with0
.When
altButton=true
, two buttons are added. If the user presses the primary button (buttonText
in the constructor), the callback will still be called with0
. If the user presses the alternate button (altButtonText
in the constructor), the callback will be called with1
.
-
enum