Struct DialogBox

Source
pub struct DialogBox { /* private fields */ }
Expand description

A struct representing a dialog box.

This struct provides a simple interface for creating and showing different types of dialog boxes, such as message boxes or question boxes. Once a dialog box is created using the DialogBox::new method, it can be shown to the user using the DialogBox::show method.

§Examples

Showing a simple dialog box:

use my_{DialogBox, DialogType};

let mut dialog_box = DialogBox::new("My App", "Hello World", DialogType::Simple);
dialog_box.show();

§Safety

Showing the same dialog box more than once is undefined behavior and depending on the platform, may or may not raise an error.

§FFI

Corresponds to NvdDialogBox.

Implementations§

Source§

impl DialogBox

Source

pub fn new<S: AsRef<str>>( title: S, msg: S, dialog_type: DialogType, ) -> Result<Self, Error>

Creates a new instance of DialogBox with the given title, msg and dialog_type.

§Arguments
  • title - The title of the dialog box.

  • msg - The message to display in the dialog box.

  • dialog_type - The type of dialog box to display, either Simple, Warning or Error.

§Returns

Returns Ok(DialogBox) if the dialog box was successfully created, otherwise returns Err(Error) with the error converted from NvDialog’s error code.

§Panics

This function will panic if CString::new fails to convert the given title or msg to a null-terminated byte string.

Examples found in repository?
examples/dialog.rs (lines 31-35)
28fn main() {
29    nvdialog_rs::init().expect("failed to initialize nvdialog");
30
31    let mut dialog_box = DialogBox::new(
32        "Hello World (from Rust!)",
33        "A very basic dialog box from Rust.",
34        DialogType::Simple,
35    )
36    .expect("Error");
37    dialog_box.show()
38}
More examples
Hide additional examples
examples/file-dialog.rs (line 46)
31fn main() {
32    nvdialog_rs::init().expect("Can't initialize NvDialog");
33    let mut file_dialog = FileDialog::new(
34        String::from("Select an image"),
35        FileDialogType::OpenFile,
36        Some(vec![
37            "png".to_owned(),
38            "jpg".to_owned(),
39            "jpeg".to_owned(),
40            "ico".to_owned(),
41            "webp".to_owned(),
42        ]),
43    );
44
45    if let Some(file) = file_dialog.retrieve_filename() {
46        DialogBox::new("File chosen", &file.to_str().unwrap(), DialogType::Simple)
47            .expect("Can't create dialog")
48            .show()
49    } else {
50        DialogBox::new("Error", "No file chosen", DialogType::Error)
51            .expect("Can't create dialog")
52            .show()
53    }
54}
Source

pub fn set_accept_label<S: AsRef<str>>(&mut self, label: S)

Source

pub fn show(&mut self)

Displays the dialog box on the screen.

This function shows the dialog box on the screen, allowing the user to interact with it. It should be called after setting any necessary options and buttons on the dialog. This function is unsafe, because it uses FFI to call C code that might not be safe.

Examples found in repository?
examples/dialog.rs (line 37)
28fn main() {
29    nvdialog_rs::init().expect("failed to initialize nvdialog");
30
31    let mut dialog_box = DialogBox::new(
32        "Hello World (from Rust!)",
33        "A very basic dialog box from Rust.",
34        DialogType::Simple,
35    )
36    .expect("Error");
37    dialog_box.show()
38}
More examples
Hide additional examples
examples/file-dialog.rs (line 48)
31fn main() {
32    nvdialog_rs::init().expect("Can't initialize NvDialog");
33    let mut file_dialog = FileDialog::new(
34        String::from("Select an image"),
35        FileDialogType::OpenFile,
36        Some(vec![
37            "png".to_owned(),
38            "jpg".to_owned(),
39            "jpeg".to_owned(),
40            "ico".to_owned(),
41            "webp".to_owned(),
42        ]),
43    );
44
45    if let Some(file) = file_dialog.retrieve_filename() {
46        DialogBox::new("File chosen", &file.to_str().unwrap(), DialogType::Simple)
47            .expect("Can't create dialog")
48            .show()
49    } else {
50        DialogBox::new("Error", "No file chosen", DialogType::Error)
51            .expect("Can't create dialog")
52            .show()
53    }
54}

Trait Implementations§

Source§

impl Drop for DialogBox

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.