Struct cursive::views::EditView
[−]
[src]
pub struct EditView { // some fields omitted }
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::empty() .title("Enter your name") .padding((1, 1, 1, 0)) .content(EditView::new() .on_submit(show_popup) .with_id("name") .fixed_width(20)) .button("Ok", |s| { let name = s.find_id::<EditView>("name") .unwrap() .get_content(); 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::new(TextView::new(content)) .button("Quit", |s| s.quit())); } }
Methods
impl EditView
[src]
fn new() -> Self
Creates a new, empty edit view.
fn set_secret(&mut self, secret: bool)
If secret
is true
, the content won't be displayed in clear.
Only *
will be shown.
fn secret(self) -> Self
Hides the content of the view.
Only *
will be shown.
fn disable(&mut self)
Disables this view.
A disabled view cannot be selected.
fn disabled(self) -> Self
Disables this view.
Chainable variant.
fn enable(&mut self)
Re-enables this view.
fn on_edit<F: Fn(&mut Cursive, &str, usize) + 'static>(self, callback: F) -> Self
Sets a callback to be called whenever the content is modified.
callback
will be called with the view
content and the current cursor position.
fn on_submit<F: Fn(&mut Cursive, &str) + 'static>(self, callback: F) -> Self
Sets a callback to be called when <Enter>
is pressed.
callback
will be given the content of the view.
fn set_enabled(&mut self, enabled: bool)
Enable or disable this view.
fn is_enabled(&self) -> bool
Returns true
if this view is enabled.
fn set_content(&mut self, content: &str)
Replace the entire content of the view with the given one.
fn get_content(&self) -> Rc<String>
Get the current text.
fn content(self, content: &str) -> Self
Sets the current content to the given value.
Convenient chainable method.
fn insert(&mut self, ch: char)
Insert ch
at the current cursor position.
fn remove(&mut self, len: usize)
Remove the character at the current cursor position.
Trait Implementations
impl Default for EditView
[src]
impl View for EditView
[src]
fn draw(&self, printer: &Printer)
Draws the view with the given printer (includes bounds) and focus.
fn layout(&mut self, size: Vec2)
Called once the size for this view has been decided, Read more
fn take_focus(&mut self, _: Direction) -> bool
This view is offered focus. Will it take it? Read more
fn on_event(&mut self, event: Event) -> EventResult
Called when a key was pressed. Default implementation just ignores it.
fn get_min_size(&mut self, constraint: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions. Read more
fn needs_relayout(&self) -> bool
Returns true
if the view content changed since last layout phase. Read more
fn find(&mut self, &Selector) -> Option<&mut Any>
Finds the view pointed to by the given path. Read more