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

Input box where the user can enter and edit text.

Examples

From the edit example.

let mut siv = Cursive::new();

// Create a dialog with an edit text and a button.
// The user can either hit the <Ok> button,
// or press Enter on the edit text.
siv.add_layer(
    Dialog::new()
        .title("Enter your name")
        .padding_lrtb(1, 1, 1, 0)
        .content(
            EditView::new()
                .on_submit(show_popup)
                .with_name("name")
                .fixed_width(20),
        )
        .button("Ok", |s| {
            let name = s
                .call_on_name("name", |view: &mut EditView| {
                    view.get_content()
                })
                .unwrap();
            show_popup(s, &name);
        }),
);

fn show_popup(s: &mut Cursive, name: &str) {
    if name.is_empty() {
        s.add_layer(Dialog::info("Please enter a name!"));
    } else {
        let content = format!("Hello {}!", name);
        s.pop_layer();
        s.add_layer(
            Dialog::around(TextView::new(content))
                .button("Quit", |s| s.quit()),
        );
    }
}

Implementations

Disables this view.

A disabled view cannot be selected.

Disables this view.

Chainable variant.

Re-enables this view.

Enable or disable this view.

Enable or disable this view.

Chainable variant.

Returns true if this view is enabled.

Creates a new, empty edit view.

Sets a maximum width for the content.

Input will be rejected if it would make the content exceed this width.

Giving None means no maximum width is applied.

Sets a maximum width for the content.

Input will be rejected if it would make the content exceed this width.

Chainable variant.

If secret is true, the content won’t be displayed in clear.

Only * will be shown.

Hides the content of the view.

Only * will be shown.

Sets the character to fill in blank space.

Defaults to “_”.

Sets the character to fill in blank space.

Chainable variant.

Examples
let edit = EditView::new().filler(" ");

Sets the style used for this view.

When the view is enabled, the style will be reversed.

Defaults to ColorStyle::Secondary.

Sets the style used for this view.

When the view is enabled, the style will be reversed.

Chainable variant.

Sets a mutable callback to be called whenever the content is modified.

callback will be called with the view content and the current cursor position.

Warning: this callback cannot be called recursively. If you somehow trigger this callback again in the given closure, it will be ignored.

If you don’t need a mutable closure but want the possibility of recursive calls, see set_on_edit.

Sets a callback to be called whenever the content is modified.

callback will be called with the view content and the current cursor position.

This callback can safely trigger itself recursively if needed (for instance if you call on_event on this view from the callback).

If you need a mutable closure and don’t care about the recursive aspect, see set_on_edit_mut.

Sets a mutable callback to be called whenever the content is modified.

Chainable variant. See set_on_edit_mut.

Sets a callback to be called whenever the content is modified.

Chainable variant. See set_on_edit.

Examples
use cursive_core::views::{EditView, TextContent, TextView};
// Keep the length of the text in a separate view.
let mut content = TextContent::new("0");
let text_view = TextView::new_with_content(content.clone());

let on_edit = EditView::new().on_edit(move |_s, text, _cursor| {
    content.set_content(format!("{}", text.len()));
});

Sets a mutable callback to be called when <Enter> is pressed.

callback will be given the content of the view.

Warning: this callback cannot be called recursively. If you somehow trigger this callback again in the given closure, it will be ignored.

If you don’t need a mutable closure but want the possibility of recursive calls, see set_on_submit.

Sets a callback to be called when <Enter> is pressed.

callback will be given the content of the view.

This callback can safely trigger itself recursively if needed (for instance if you call on_event on this view from the callback).

If you need a mutable closure and don’t care about the recursive aspect, see set_on_submit_mut.

Sets a mutable callback to be called when <Enter> is pressed.

Chainable variant.

Sets a callback to be called when <Enter> is pressed.

Chainable variant.

Examples
use cursive_core::views::{Dialog, EditView};

let edit_view = EditView::new().on_submit(|s, text| {
    s.add_layer(Dialog::info(text));
});

Replace the entire content of the view with the given one.

Returns a callback in response to content change.

You should run this callback with a &mut Cursive.

Get the current text.

Sets the current content to the given value.

Convenient chainable method.

Does not run the on_edit callback.

Sets the cursor position.

Insert ch at the current cursor position.

Returns a callback in response to content change.

You should run this callback with a &mut Cursive.

Remove the character at the current cursor position.

Returns a callback in response to content change.

You should run this callback with a &mut Cursive.

Trait Implementations

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

Draws the view with the given printer (includes bounds) and focus. Read more

Called once the size for this view has been decided. Read more

Attempt to give this view the focus. Read more

Called when an event is received (key press, mouse event, …). Read more

What part of the view is important and should be visible? Read more

Should return true if the view content changed since the last call to layout(). Read more

Returns the minimum size the view requires with the given restrictions. Read more

Runs a closure on the view identified by the given selector. Read more

Moves the focus to the view identified by the given selector. Read more

Returns the type of this view. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Downcast self to a Any.

Downcast self to a mutable Any.

Returns a boxed any from a boxed self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Runs a callback on all views identified by sel. Read more

Runs a callback on the view identified by sel. Read more

Convenient method to use call_on with a view::Selector::Name.

Convenient method to find a view wrapped in an NamedView.

Returns the argument unchanged.

Calls U::from(self).

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

Returns a Box<View>.

Wraps this view into an NamedView with the given id. Read more

Wraps self in a ResizedView with the given size constraints.

Wraps self into a fixed-size ResizedView.

Wraps self into a fixed-width ResizedView.

Wraps self into a fixed-width ResizedView.

Wraps self into a full-screen ResizedView.

Wraps self into a full-width ResizedView.

Wraps self into a full-height ResizedView.

Wraps self into a limited-size ResizedView.

Wraps self into a limited-width ResizedView.

Wraps self into a limited-height ResizedView.

Wraps self into a ResizedView at least sized size.

Wraps self in a ResizedView at least min_width wide.

Wraps self in a ResizedView at least min_height tall.

Should always be Self

Wraps self in a ScrollView.

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.

Calls the given closure and return the result. Read more

Calls the given closure on self.

Calls the given closure on self.

Calls the given closure if condition == true.