InputBox

Struct InputBox 

Source
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

Source

pub fn new<S: AsRef<str>>(title: S, prompt: S) -> Self

Examples found in repository?
examples/input_box.rs (lines 35-38)
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}
Source

pub fn display(&mut self)

Examples found in repository?
examples/input_box.rs (line 39)
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}
Source

pub fn get_input(&mut self) -> Option<DynamicString>

Examples found in repository?
examples/input_box.rs (line 40)
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 Drop for InputBox

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Object for InputBox

Source§

type NativeType = _NvdInputBox

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) -> Self::ReturnValue

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.