pub struct Entry { /* private fields */ }
Expand description

A field for reading text input from the user.

An EntryFilter can be use to filter characters as the user enters them into the Entry.

Example

extern crate newt;
use newt::callbacks::EntryFilter;
use newt::prelude::*;

pub fn main() {
    newt::init().unwrap();
    newt::cls();
    newt::centered_window(22, 5, None).unwrap();

    // last character entered
    let mut g_ch: char = '\0';
    // last cursor position
    let mut g_cursor: i32 = 0;
    // user data from last Entry modified
    let mut g_data: i32 = 0;

    // Create closure to be used to filter the Entry field.
    let mut f = |_e: &Entry, data: Option<&i32>, ch: char, cursor: i32| {
        g_data = *data.unwrap(); // set user data
        g_ch = ch;               // set character entered
        g_cursor = cursor;       // set cursor position

        // The returned character gets added to the entry.
        // If for example you want to fill an entry with asterisks despite
        // what the user entered, then return '*' here.
        return ch; // Return the entered character.
    };

    let l1 = Label::new(1, 1, "Entry 1:");
    let l2 = Label::new(1, 2, "Entry 2:");
    let e1 = Entry::new(10, 1, None, 10, 0);
    let e2 = Entry::new(10, 2, None, 10, 0);
    let ok = CompactButton::new(7, 4, "Ok");
    let components: &[&dyn Component] = &[&l1, &l2, &e1, &e2, &ok];

    let mut form = Form::new(None, 0);
    form.add_components(components).unwrap();

    // Filter the first Entry, passing user data `5`.
    let mut filter = EntryFilter::new(&e1, Some(5), &mut f);
    // Filter the second Entry, passing user data `10`.
    filter.add_entry(&e2, Some(10));

    form.run().unwrap();
    newt::finished();

    println!("Entry 1: {}", e1.get_text());
    println!("Entry 2: {}", e2.get_text());

    // Display the last values set by the filter.
    println!("ch = {}", g_ch);
    println!("cursor = {}", g_cursor);
    println!("data = {}", g_data);
}

Implementations

Trait Implementations

Return newtComponent pointer.

Executes the destructor for this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Allow the Widget to be focused when its parent Form is run. Read more

Get the position of the Widget’s top left corner. Read more

Get the Widget’s width and height. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.