pub struct Input {
    pub title: Spans,
    pub border: Style,
    pub on_key: KeyHandler,
    pub on_mouse: MouseHandler,
}
Available on crate feature experimental only.
Expand description

A single-line input component with cursor controls.

This is a smart input box with the following features:

  • rendering a cursor
  • scrolling on overflow
  • supports navigating with arrow keys
  • supports navigating with ctrl+a and ctrl+e
  • has a fixed single-line height of 3 rows

Vertical Alignment

Since this component always renders as three blocks high, when more space is available it vertically centers itself. In order to align this element to the top, you will need to use VStack along with Flex::Block and properly route the key events:

#[component(Root)]
fn render() {
  let input: element::Any = render! {
    Input(title: "Input Box")
  };

  let on_key = on_key! { [input]
    KeyEvent { code: Esc, .. } => event::quit(),
    event => input.on_key(event),
  };

  render! {
    VStack(flex: [Block(3), Grow(1)], on_key) {
      Embed(content: input)
      Empty()
    }
  }
}

Fields§

§title: Spans§border: Style§on_key: KeyHandler§on_mouse: MouseHandler

Implementations§

source§

impl Input

source

pub fn new( title: Spans, border: Style, on_key: KeyHandler, on_mouse: MouseHandler ) -> Any

Trait Implementations§

source§

impl Component for Input

source§

fn render(&self) -> Any

source§

impl Default for Input

source§

fn default() -> Input

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Input

§

impl Send for Input

§

impl Sync for Input

§

impl Unpin for Input

§

impl !UnwindSafe for Input

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.