pub struct InputBox { /* private fields */ }Expand description
A struct representing an input box.
Input boxes are similar to DialogBox ones but instead of just showing text, they also allow the user to
provide some text input. The input field is always single-line. In addition, the InputBox can display some optional text
to provide more information to the user (Like “Enter your name here”).
§Examples
Showing a simple input box, then retrieving the input:
use std::process::abort;
use nvdialog_rs::InputBox;
nvdialog_rs::init().unwrap_or_else(|e| {
eprintln!("Failed to initialize NvDialog: {}", e.to_string());
abort();
});
let mut input_box = InputBox::new(
"Input Box",
"Please enter some text here. The text will be printed to stdout.",
);
input_box.display();
let input = input_box.get_input();
if let Some(string) = input {
println!("You entered the following text: \"{}\"", string);
} else {
eprintln!("You didn't enter anything!");
}§Safety
The returned string’s contents, as described in the NvDialog documentation, is heap-allocated, and therefore it’s safe to modify this string through methods inside the struct. However, any modifications are applied to the original string DIRECTLY, meaning that if you wish to preserve the original string but still modify it somewhere, you should duplicate it instead.
§FFI
Corresponds to NvdInputBox.
Implementations§
Source§impl InputBox
impl InputBox
Sourcepub fn new<S: AsRef<str>>(title: S, prompt: S) -> Self
pub fn new<S: AsRef<str>>(title: S, prompt: S) -> Self
Examples found in repository?
29fn main() {
30 nvdialog_rs::init().unwrap_or_else(|e| {
31 eprintln!("Failed to initialize NvDialog: {}", e.to_string());
32 abort();
33 });
34
35 let mut input_box = InputBox::new(
36 "Input Box",
37 "Please enter some text here. The text will be printed to stdout.",
38 );
39 input_box.display();
40 let input = input_box.get_input();
41 if let Some(string) = input {
42 println!("You entered the following text: \"{}\"", string.to_string());
43 } else {
44 eprintln!("You didn't enter anything!");
45 }
46}Sourcepub fn display(&mut self)
pub fn display(&mut self)
Examples found in repository?
29fn main() {
30 nvdialog_rs::init().unwrap_or_else(|e| {
31 eprintln!("Failed to initialize NvDialog: {}", e.to_string());
32 abort();
33 });
34
35 let mut input_box = InputBox::new(
36 "Input Box",
37 "Please enter some text here. The text will be printed to stdout.",
38 );
39 input_box.display();
40 let input = input_box.get_input();
41 if let Some(string) = input {
42 println!("You entered the following text: \"{}\"", string.to_string());
43 } else {
44 eprintln!("You didn't enter anything!");
45 }
46}Sourcepub fn get_input(&mut self) -> Option<DynamicString>
pub fn get_input(&mut self) -> Option<DynamicString>
Examples found in repository?
29fn main() {
30 nvdialog_rs::init().unwrap_or_else(|e| {
31 eprintln!("Failed to initialize NvDialog: {}", e.to_string());
32 abort();
33 });
34
35 let mut input_box = InputBox::new(
36 "Input Box",
37 "Please enter some text here. The text will be printed to stdout.",
38 );
39 input_box.display();
40 let input = input_box.get_input();
41 if let Some(string) = input {
42 println!("You entered the following text: \"{}\"", string.to_string());
43 } else {
44 eprintln!("You didn't enter anything!");
45 }
46}Trait Implementations§
Source§impl Object for InputBox
impl Object for InputBox
Source§type NativeType = _NvdInputBox
type NativeType = _NvdInputBox
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) -> Self::ReturnValue
fn show(&self) -> Self::ReturnValue
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.