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- AQuestionDialogButtonsenum 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 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(&self) -> Reply
pub fn get_reply(&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 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}Trait Implementations§
Source§impl Drop for QuestionDialog
impl Drop for QuestionDialog
Source§impl Object for QuestionDialog
impl Object for QuestionDialog
Source§type NativeType = _NvdQuestionBox
type NativeType = _NvdQuestionBox
NvDialog. It will be used as a pointer
to provide compatibility with the NvDialog API.Source§type ReturnValue = Reply
type ReturnValue = Reply
Self::show. It should match the value that the dialog returns when
it is presented to the user.Source§fn get_raw(&self) -> *mut NvdQuestionBox
fn get_raw(&self) -> *mut NvdQuestionBox
null.Source§fn show(&self) -> Reply
fn show(&self) -> Reply
Self::ReturnValue is not () then it will also return that value.
Sometimes this serves as an alias to the type’s implementation of the analogous function. If you cannot afford the overhead,
you can use that instead.