Struct cursive::views::EditView [−][src]
pub struct EditView { /* fields omitted */ }
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
Enable or disable this view.
Enable or disable this view.
Chainable variant.
Returns true
if this view is enabled.
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.
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()));
});
pub fn set_on_submit_mut<F>(&mut self, callback: F) where
F: 'static + FnMut(&mut Cursive, &str),
pub fn set_on_submit_mut<F>(&mut self, callback: F) where
F: 'static + FnMut(&mut Cursive, &str),
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
.
Trait Implementations
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
Auto Trait Implementations
impl !RefUnwindSafe for EditView
impl !UnwindSafe for EditView
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘ
pub fn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘ
Returns a Box<View>
.
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.
Wraps self
in a ScrollView
.
Calls the given closure and return the result. Read more
Calls the given closure on self
.