QuestionDialog

Struct QuestionDialog 

Source
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

Source

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 - A QuestionDialogButtons 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?
examples/question-dialog.rs (lines 31-35)
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}
Source

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?
examples/question-dialog.rs (line 36)
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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Object for QuestionDialog

Source§

type NativeType = _NvdQuestionBox

The type of the underlying native object, created by NvDialog. It will be used as a pointer to provide compatibility with the NvDialog API.
Source§

type ReturnValue = Reply

The value that should be returned from 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

Returns the raw object created by NvDialog internally. This should never return null.
Source§

fn show(&self) -> Reply

Presents the dialog to the user. If 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.
Source§

fn free(&mut self)

Frees the underlying native object. This should not be usually called manually, instead the Drop implementation should handle it when the time is correct. Be wary, if you do call this, you might run into double freeing errors.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.