MessageBox
A window showing some text and buttons.
Header | #include "nativeui/message_box.h" |
Namespace | namespace nu |
Type | class (RefCounted) |
Constructors
MessageBox()
Create a message box.
Methods
int Run()
Show the message box and wait for result. Response ID will be returned.
Return
int
int RunForWindow(Window* window)
Show the message box as a child for window
and wait for result.
Response ID will be returned.
Parameters
Window*
window
Return
int
Windows Linux
void Show()Show the message box. The on_response
event will be emitted when
the message box is closed.
void ShowForWindow(Window* window)
Show the message box as a child of window
. The on_response
event will be emitted when the message box is closed.
Parameters
Window*
window
void Close()
Close the message box. The cancel response ID will be used as result.
void SetType(MessageBox::Type type)
Set the type
of message box, system will show the corresponding icon in
the message box.
On macOS there is no visual difference between information
and warning
types.
On Linux this method has no effect if a custom icon has been set.
Parameters
MessageBox::Type
type
Windows Linux
void SetTitle(const std::string& title)Set the message box window's title.
Parameters
const std::string&
title
void AddButton(const std::string& title, int response)
Add a button with title
. The response
ID will be used as result when
the button is clicked.
Parameters
const std::string&
titleint
response
void SetDefaultResponse(int response)
Set the default response
ID, when user presses the Enter key
the button associated with the ID will be clicked.
Parameters
int
response
void SetCancelResponse(int response)
Set the cancel response
ID that will be used as result when user
presses the Esc key or when the window is closed without
clicking any button.
The default cancel response ID is -1.
Parameters
int
response
void SetText(const std::string& text)
Set the message box's message text.
Parameters
const std::string&
text
void SetInformativeText(const std::string& text)
Set informative text that will show bellow the message text.
Parameters
const std::string&
text
macOS Linux
void SetAccessoryView(scoped_refptr<View> view)Set the accessory view
that will be placed between the text and the
buttons. The view
must be given a size before being used as accessory
view.
Parameters
scoped_refptr<View>
view
macOS Linux
View* GetAccessoryView() constReturn the accessory view.
Return
View*
void SetImage(scoped_refptr<Image> image)
Set the custom icon displayed in the message box.
On macOS the default icon is the app's icon, on Windows and Linux there is no default icon.
Parameters
scoped_refptr<Image>
image
Image* GetImage() const
Return the custom icon.
Return
Image*
NativeMessageBox GetNative() const
Return the native instance wrapped by the class.
Return
NativeMessageBox
Events
void on_response(MessageBox* self, int response)
Emitted when the message box is closed.
Parameters
MessageBox*
selfint
response