pub struct QuestionDialog { /* private fields */ }
Expand description
A dialog box for asking a question and getting a response from the user.
This struct wraps the underlying C API for creating a question dialog box. It provides a high-level interface for displaying a dialog box, getting a response from the user, and destroying the dialog box.
§Examples
let question_dialog = QuestionDialog::new(
"Are you sure you want to delete this file?",
"This action cannot be undone.",
QuestionDialogButtons::YesNo,
);
let reply = question_dialog.get_reply();
match result {
Reply::Accepted => {
// The user clicked "Yes". Delete the file...
}
Reply::Rejected => {
// The user clicked "No". Do not delete the file...
}
Reply::Cancelled => {
// The user clicked "Cancel". Do not delete the file...
}
}
§Safety
This function converts the C enum for the reply (See
NvdReply
)
into the crate’s Reply
type using the
From<i32>
trait. This is generally safe, however, keep in mind that invalid
or garbage values returned by some other, unrelated unsafe code may actually bypass
the Rust safety rules.
For further information see the documentation of Reply
.
§FFI
Corresponds to NvdQuestionBox
.
Implementations§
Source§impl QuestionDialog
impl QuestionDialog
Sourcepub fn new<S: AsRef<str>>(
title: S,
msg: S,
buttons: QuestionDialogButtons,
) -> Self
pub fn new<S: AsRef<str>>( title: S, msg: S, buttons: QuestionDialogButtons, ) -> Self
Creates a new QuestionDialog
with the specified title, message, and
buttons.
§Arguments
title
- A string slice or reference that contains the title of the dialog box.msg
- A string slice or reference that contains the message to display in the dialog box.buttons
- AQuestionDialogButtons
enum that specifies the buttons to display in the dialog box.
§Examples
let question_dialog = QuestionDialog::new(
"Are you sure you want to delete this file?",
"This action cannot be undone.",
QuestionDialogButtons::YesNo,
);
Examples found in repository?
29fn main() {
30 nvdialog_rs::init().expect("failed to initialize nvdialog");
31 let mut dialog = QuestionDialog::new(
32 "Which message should be shown?",
33 "Select between Yes/No/Cancel please.",
34 QuestionDialogButtons::YesNoCancel,
35 );
36 match dialog.get_reply() {
37 nvdialog_rs::Reply::Accepted => println!("Yes selected."),
38 nvdialog_rs::Reply::Cancelled => println!("Cancel selected."),
39 nvdialog_rs::Reply::Rejected => println!("No selected."),
40 }
41}
Sourcepub fn get_reply(&mut self) -> Reply
pub fn get_reply(&mut self) -> Reply
Returns the user’s reply to the question displayed in the dialog box.
§Examples
let question_dialog = QuestionDialog::new(
"Are you sure you want to delete this file?",
"This action cannot be undone.",
QuestionDialogButtons::YesNo,
);
let reply = question_dialog.get_reply();
if reply == Reply::Yes {
// Delete the file.
} else {
// Do nothing.
}
Examples found in repository?
29fn main() {
30 nvdialog_rs::init().expect("failed to initialize nvdialog");
31 let mut dialog = QuestionDialog::new(
32 "Which message should be shown?",
33 "Select between Yes/No/Cancel please.",
34 QuestionDialogButtons::YesNoCancel,
35 );
36 match dialog.get_reply() {
37 nvdialog_rs::Reply::Accepted => println!("Yes selected."),
38 nvdialog_rs::Reply::Cancelled => println!("Cancel selected."),
39 nvdialog_rs::Reply::Rejected => println!("No selected."),
40 }
41}