DialogBox

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

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

Trait Implementations§

Source§

impl Drop for DialogBox

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Object for DialogBox

Source§

type NativeType = _NvdDialogBox

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 = ()

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 Self::NativeType

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

fn show(&self)

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.