Struct cursive::views::EditView [−][src]
pub struct EditView { /* fields omitted */ }
Input box where the user can enter and edit text.
Examples
From the edit example.
let mut siv = Cursive::dummy(); // 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((1, 1, 1, 0)) .content( EditView::new() .on_submit(show_popup) .with_id("name") .fixed_width(20), ) .button("Ok", |s| { let name = s.call_on_id( "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())); } }
Methods
impl EditView
[src]
impl EditView
pub fn new() -> Self
[src]
pub fn new() -> Self
Creates a new, empty edit view.
pub fn set_max_content_width(&mut self, width: Option<usize>)
[src]
pub fn set_max_content_width(&mut self, width: Option<usize>)
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.
pub fn max_content_width(self, width: usize) -> Self
[src]
pub fn max_content_width(self, width: usize) -> Self
Sets a maximum width for the content.
Input will be rejected if it would make the content exceed this width.
Chainable variant.
pub fn set_secret(&mut self, secret: bool)
[src]
pub fn set_secret(&mut self, secret: bool)
If secret
is true
, the content won't be displayed in clear.
Only *
will be shown.
pub fn secret(self) -> Self
[src]
pub fn secret(self) -> Self
Hides the content of the view.
Only *
will be shown.
pub fn set_filler<S: Into<String>>(&mut self, filler: S)
[src]
pub fn set_filler<S: Into<String>>(&mut self, filler: S)
Sets the character to fill in blank space.
Defaults to "_".
pub fn filler<S: Into<String>>(self, filler: S) -> Self
[src]
pub fn filler<S: Into<String>>(self, filler: S) -> Self
Sets the character to fill in blank space.
Chainable variant.
Examples
let edit = EditView::new().filler(" ");
pub fn disable(&mut self)
[src]
pub fn disable(&mut self)
Disables this view.
A disabled view cannot be selected.
pub fn disabled(self) -> Self
[src]
pub fn disabled(self) -> Self
Disables this view.
Chainable variant.
pub fn enable(&mut self)
[src]
pub fn enable(&mut self)
Re-enables this view.
pub fn set_style(&mut self, style: ColorStyle)
[src]
pub fn set_style(&mut self, style: ColorStyle)
Sets the style used for this view.
When the view is enabled, the style will be reversed.
Defaults to ColorStyle::Secondary
.
pub fn style(self, style: ColorStyle) -> Self
[src]
pub fn style(self, style: ColorStyle) -> Self
Sets the style used for this view.
When the view is enabled, the style will be reversed.
Chainable variant.
pub fn set_on_edit_mut<F>(&mut self, callback: F) where
F: FnMut(&mut Cursive, &str, usize) + 'static,
[src]
pub fn set_on_edit_mut<F>(&mut self, callback: F) where
F: FnMut(&mut Cursive, &str, usize) + 'static,
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
.
pub fn set_on_edit<F>(&mut self, callback: F) where
F: Fn(&mut Cursive, &str, usize) + 'static,
[src]
pub fn set_on_edit<F>(&mut self, callback: F) where
F: Fn(&mut Cursive, &str, usize) + 'static,
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
.
pub fn on_edit_mut<F>(self, callback: F) -> Self where
F: FnMut(&mut Cursive, &str, usize) + 'static,
[src]
pub fn on_edit_mut<F>(self, callback: F) -> Self where
F: FnMut(&mut Cursive, &str, usize) + 'static,
Sets a mutable callback to be called whenever the content is modified.
Chainable variant. See set_on_edit_mut
.
pub fn on_edit<F>(self, callback: F) -> Self where
F: Fn(&mut Cursive, &str, usize) + 'static,
[src]
pub fn on_edit<F>(self, callback: F) -> Self where
F: Fn(&mut Cursive, &str, usize) + 'static,
Sets a callback to be called whenever the content is modified.
Chainable variant. See set_on_edit
.
pub fn set_on_submit_mut<F>(&mut self, callback: F) where
F: FnMut(&mut Cursive, &str) + 'static,
[src]
pub fn set_on_submit_mut<F>(&mut self, callback: F) where
F: FnMut(&mut Cursive, &str) + 'static,
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
.
pub fn set_on_submit<F>(&mut self, callback: F) where
F: Fn(&mut Cursive, &str) + 'static,
[src]
pub fn set_on_submit<F>(&mut self, callback: F) where
F: Fn(&mut Cursive, &str) + 'static,
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
.
pub fn on_submit_mut<F>(self, callback: F) -> Self where
F: FnMut(&mut Cursive, &str) + 'static,
[src]
pub fn on_submit_mut<F>(self, callback: F) -> Self where
F: FnMut(&mut Cursive, &str) + 'static,
Sets a mutable callback to be called when <Enter>
is pressed.
Chainable variant.
pub fn on_submit<F>(self, callback: F) -> Self where
F: Fn(&mut Cursive, &str) + 'static,
[src]
pub fn on_submit<F>(self, callback: F) -> Self where
F: Fn(&mut Cursive, &str) + 'static,
Sets a callback to be called when <Enter>
is pressed.
Chainable variant.
pub fn set_enabled(&mut self, enabled: bool)
[src]
pub fn set_enabled(&mut self, enabled: bool)
Enable or disable this view.
pub fn is_enabled(&self) -> bool
[src]
pub fn is_enabled(&self) -> bool
Returns true
if this view is enabled.
pub fn set_content<S: Into<String>>(&mut self, content: S) -> Callback
[src]
pub fn set_content<S: Into<String>>(&mut self, content: S) -> Callback
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
.
pub fn get_content(&self) -> Rc<String>
[src]
pub fn get_content(&self) -> Rc<String>
Get the current text.
pub fn content<S: Into<String>>(self, content: S) -> Self
[src]
pub fn content<S: Into<String>>(self, content: S) -> Self
Sets the current content to the given value.
Convenient chainable method.
Does not run the on_edit
callback.
pub fn set_cursor(&mut self, cursor: usize)
[src]
pub fn set_cursor(&mut self, cursor: usize)
Sets the cursor position.
pub fn insert(&mut self, ch: char) -> Callback
[src]
pub fn insert(&mut self, ch: char) -> Callback
Insert ch
at the current cursor position.
Returns a callback in response to content change.
You should run this callback with a &mut Cursive
.
pub fn remove(&mut self, len: usize) -> Callback
[src]
pub fn remove(&mut self, len: usize) -> Callback
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
impl Default for EditView
[src]
impl Default for EditView
impl View for EditView
[src]
impl View for EditView
fn draw(&self, printer: &Printer)
[src]
fn draw(&self, printer: &Printer)
Draws the view with the given printer (includes bounds) and focus. Read more
fn layout(&mut self, size: Vec2)
[src]
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
[src]
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
[src]
fn on_event(&mut self, event: Event) -> EventResult
Called when an event is received (key press, mouse event, ...). Read more
fn important_area(&self, _: Vec2) -> Rect
[src]
fn important_area(&self, _: Vec2) -> Rect
What part of the view is important and should be visible? Read more
fn needs_relayout(&self) -> bool
[src]
fn needs_relayout(&self) -> bool
Returns true
if the view content changed since last layout phase. Read more
fn required_size(&mut self, constraint: Vec2) -> Vec2
[src]
fn required_size(&mut self, constraint: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions. Read more
fn call_on_any<'a>(&mut self, _: &Selector, _: AnyCb<'a>)
[src]
fn call_on_any<'a>(&mut self, _: &Selector, _: AnyCb<'a>)
Runs a closure on the view identified by the given selector. Read more
fn focus_view(&mut self, &Selector) -> Result<(), ()>
[src]
fn focus_view(&mut self, &Selector) -> Result<(), ()>
Moves the focus to the view identified by the given selector. Read more