Struct Entry

Source
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§

Source§

impl Entry

Source

pub fn new( left: i32, top: i32, initial_value: Option<&str>, width: i32, flags: i32, ) -> Entry

Create a new Entry.

  • left - The left-most position of the Entry.
  • top - The top-most position of the Entry.
  • initial_value - The optional inital text of the Entry.
  • width - The width of the Entry.
  • flags - Flags modifying the behavior of the Entry. See also generalized flags.
Source

pub fn get_text(&self) -> String

Get the text currently in the Entry.

Source

pub fn set_text(&self, text: &str, cursor_at_end: bool)

Set the current text in the Entry.

  • text - The text to enter into the Entry.
  • cursor_at_end - Move the cursor to the end of the string after setting the text.
Source

pub fn set_flags(&self, flags: i32, sense: FlagsSense)

Set flags modifying the Entry’s behavior.

See Entry flags as well as flags for possible flags.

  • flags - A logical ored list of flags.
  • sense - The operation used to set the flags (Set, Reset, or Toggle).
Source

pub fn set_colors(&self, normal: i32, disabled: i32)

Set the colors of the Entry.

See COLORSET_CUSTOM for defining new color sets.

  • normal - The color set to use when in a normal state.
  • active - The color set to use when activated or selected.
Source

pub fn get_cursor_position(&self) -> i32

Get the current cursor position in the Entry.

Source

pub fn set_cursor_position(&self, position: i32)

Set the current cursor position in the Entry.

Trait Implementations§

Source§

impl Component for Entry

Source§

fn co(&self) -> newtComponent

Return newtComponent pointer.
Source§

impl Drop for Entry

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq<Box<dyn Component>> for Entry

Source§

fn eq(&self, other: &Box<dyn Component>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<ExitReason> for Entry

Source§

fn eq(&self, other: &ExitReason) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Rhs: Component> PartialEq<Rhs> for Entry

Source§

fn eq(&self, other: &Rhs) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl WidgetFns for Entry

Source§

fn takes_focus(&self, value: bool)

Allow the widget to be focused when its parent Form is run.
Source§

fn get_position(&self) -> (i32, i32)

Get the position of the widget’s top left corner. Read more
Source§

fn get_size(&self) -> (i32, i32)

Get the widget’s width and height. Read more

Auto Trait Implementations§

§

impl !Freeze for Entry

§

impl !RefUnwindSafe for Entry

§

impl !Send for Entry

§

impl !Sync for Entry

§

impl Unpin for Entry

§

impl UnwindSafe for Entry

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.