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
,Warning
orError
.
§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
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}
pub fn set_accept_label<S: AsRef<str>>(&mut self, label: S)
Sourcepub fn show(&mut self)
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?
More examples
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}