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
impl DialogBox
Sourcepub fn new<S: AsRef<str>>(
title: S,
msg: S,
dialog_type: DialogType,
) -> Result<Self, Error>
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, eitherSimple,WarningorError.
§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?
More examples
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}pub fn set_accept_label<S: AsRef<str>>(&mut self, label: S)
Trait Implementations§
Source§impl Object for DialogBox
impl Object for DialogBox
Source§type NativeType = _NvdDialogBox
type NativeType = _NvdDialogBox
NvDialog. It will be used as a pointer
to provide compatibility with the NvDialog API.Source§type ReturnValue = ()
type ReturnValue = ()
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
fn get_raw(&self) -> *mut Self::NativeType
null.Source§fn show(&self)
fn show(&self)
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.