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
sourceimpl EditView
impl EditView
sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Enable or disable this view.
sourcepub fn with_enabled(self, is_enabled: bool) -> EditView
pub fn with_enabled(self, is_enabled: bool) -> EditView
Enable or disable this view.
Chainable variant.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true
if this view is enabled.
sourcepub fn set_max_content_width(&mut self, width: Option<usize>)
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.
sourcepub fn max_content_width(self, width: usize) -> EditView
pub fn max_content_width(self, width: usize) -> EditView
Sets a maximum width for the content.
Input will be rejected if it would make the content exceed this width.
Chainable variant.
sourcepub fn set_secret(&mut self, secret: bool)
pub fn set_secret(&mut self, secret: bool)
If secret
is true
, the content won’t be displayed in clear.
Only *
will be shown.
sourcepub fn set_filler<S>(&mut self, filler: S)where
S: Into<String>,
pub fn set_filler<S>(&mut self, filler: S)where
S: Into<String>,
Sets the character to fill in blank space.
Defaults to “_”.
sourcepub fn filler<S>(self, filler: S) -> EditViewwhere
S: Into<String>,
pub fn filler<S>(self, filler: S) -> EditViewwhere
S: Into<String>,
Sets the character to fill in blank space.
Chainable variant.
Examples
let edit = EditView::new().filler(" ");
sourcepub fn set_style(&mut self, style: ColorStyle)
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
.
sourcepub fn style(self, style: ColorStyle) -> EditView
pub fn style(self, style: ColorStyle) -> EditView
Sets the style used for this view.
When the view is enabled, the style will be reversed.
Chainable variant.
sourcepub fn set_on_edit_mut<F>(&mut self, callback: F)where
F: 'static + FnMut(&mut Cursive, &str, usize),
pub fn set_on_edit_mut<F>(&mut self, callback: F)where
F: 'static + FnMut(&mut Cursive, &str, usize),
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
.
sourcepub fn set_on_edit<F>(&mut self, callback: F)where
F: 'static + Fn(&mut Cursive, &str, usize),
pub fn set_on_edit<F>(&mut self, callback: F)where
F: 'static + Fn(&mut Cursive, &str, usize),
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
.
sourcepub fn on_edit_mut<F>(self, callback: F) -> EditViewwhere
F: 'static + FnMut(&mut Cursive, &str, usize),
pub fn on_edit_mut<F>(self, callback: F) -> EditViewwhere
F: 'static + FnMut(&mut Cursive, &str, usize),
Sets a mutable callback to be called whenever the content is modified.
Chainable variant. See set_on_edit_mut
.
sourcepub fn on_edit<F>(self, callback: F) -> EditViewwhere
F: 'static + Fn(&mut Cursive, &str, usize),
pub fn on_edit<F>(self, callback: F) -> EditViewwhere
F: 'static + Fn(&mut Cursive, &str, usize),
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()));
});
sourcepub 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
.
sourcepub fn set_on_submit<F>(&mut self, callback: F)where
F: 'static + Fn(&mut Cursive, &str),
pub fn set_on_submit<F>(&mut self, callback: F)where
F: 'static + Fn(&mut Cursive, &str),
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
.
sourcepub fn on_submit_mut<F>(self, callback: F) -> EditViewwhere
F: 'static + FnMut(&mut Cursive, &str),
pub fn on_submit_mut<F>(self, callback: F) -> EditViewwhere
F: 'static + FnMut(&mut Cursive, &str),
Sets a mutable callback to be called when <Enter>
is pressed.
Chainable variant.
sourcepub fn on_submit<F>(self, callback: F) -> EditViewwhere
F: 'static + Fn(&mut Cursive, &str),
pub fn on_submit<F>(self, callback: F) -> EditViewwhere
F: 'static + Fn(&mut Cursive, &str),
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));
});
sourcepub fn set_content<S>(&mut self, content: S) -> Callbackwhere
S: Into<String>,
pub fn set_content<S>(&mut self, content: S) -> Callbackwhere
S: Into<String>,
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
.
sourcepub fn get_content(&self) -> Rc<String>
pub fn get_content(&self) -> Rc<String>
Get the current text.
sourcepub fn content<S>(self, content: S) -> EditViewwhere
S: Into<String>,
pub fn content<S>(self, content: S) -> EditViewwhere
S: Into<String>,
Sets the current content to the given value.
Convenient chainable method.
Does not run the on_edit
callback.
sourcepub fn set_cursor(&mut self, cursor: usize)
pub fn set_cursor(&mut self, cursor: usize)
Sets the cursor position.
Trait Implementations
sourceimpl View for EditView
impl View for EditView
sourcefn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Draws the view with the given printer (includes bounds) and focus. Read more
sourcefn layout(&mut self, size: XY<usize>)
fn layout(&mut self, size: XY<usize>)
Called once the size for this view has been decided. Read more
sourcefn take_focus(&mut self, Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, Direction) -> Result<EventResult, CannotFocus>
Attempt to give this view the focus. Read more
sourcefn on_event(&mut self, event: Event) -> EventResult
fn on_event(&mut self, event: Event) -> EventResult
Called when an event is received (key press, mouse event, …). Read more
sourcefn important_area(&self, XY<usize>) -> Rect
fn important_area(&self, XY<usize>) -> Rect
What part of the view is important and should be visible? Read more
sourcefn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
Should return true
if the view content changed since the last call
to layout()
. Read more
sourcefn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
fn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
Returns the minimum size the view requires with the given restrictions. Read more
sourcefn call_on_any(
&mut self,
&Selector<'_>,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
fn call_on_any(
&mut self,
&Selector<'_>,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
Runs a closure on the view identified by the given selector. Read more
sourcefn focus_view(&mut self, &Selector<'_>) -> Result<EventResult, ViewNotFound>
fn focus_view(&mut self, &Selector<'_>) -> Result<EventResult, ViewNotFound>
Moves the focus to the view identified by the given selector. Read more
Auto Trait Implementations
impl !RefUnwindSafe for EditView
impl !Send for EditView
impl !Sync for EditView
impl Unpin for EditView
impl !UnwindSafe for EditView
Blanket Implementations
sourceimpl<T> AnyView for Twhere
T: View,
impl<T> AnyView for Twhere
T: View,
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Downcast self to a mutable Any
.
sourcefn as_boxed_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
fn as_boxed_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
Returns a boxed any from a boxed self. Read more
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Finder for Twhere
T: View,
impl<T> Finder for Twhere
T: View,
sourcefn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)where
V: View,
F: FnMut(&mut V),
fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)where
V: View,
F: FnMut(&mut V),
Runs a callback on all views identified by sel
. Read more
sourcefn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>where
V: View,
F: FnOnce(&mut V) -> R,
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>where
V: View,
F: FnOnce(&mut V) -> R,
Runs a callback on the view identified by sel
. Read more
sourceimpl<T> IntoBoxedView for Twhere
T: View,
impl<T> IntoBoxedView for Twhere
T: View,
sourcefn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
fn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
Returns a Box<View>
.
sourceimpl<T> Resizable for Twhere
T: View,
impl<T> Resizable for Twhere
T: View,
sourcefn resized(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
fn resized(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
Wraps self
in a ResizedView
with the given size constraints.
sourcefn fixed_size<S>(self, size: S) -> ResizedView<Self>where
S: Into<XY<usize>>,
fn fixed_size<S>(self, size: S) -> ResizedView<Self>where
S: Into<XY<usize>>,
Wraps self
into a fixed-size ResizedView
.
sourcefn fixed_width(self, width: usize) -> ResizedView<Self>
fn fixed_width(self, width: usize) -> ResizedView<Self>
Wraps self
into a fixed-width ResizedView
.
sourcefn fixed_height(self, height: usize) -> ResizedView<Self>
fn fixed_height(self, height: usize) -> ResizedView<Self>
Wraps self
into a fixed-width ResizedView
.
sourcefn full_screen(self) -> ResizedView<Self>
fn full_screen(self) -> ResizedView<Self>
Wraps self
into a full-screen ResizedView
.
sourcefn full_width(self) -> ResizedView<Self>
fn full_width(self) -> ResizedView<Self>
Wraps self
into a full-width ResizedView
.
sourcefn full_height(self) -> ResizedView<Self>
fn full_height(self) -> ResizedView<Self>
Wraps self
into a full-height ResizedView
.
sourcefn max_size<S>(self, size: S) -> ResizedView<Self>where
S: Into<XY<usize>>,
fn max_size<S>(self, size: S) -> ResizedView<Self>where
S: Into<XY<usize>>,
Wraps self
into a limited-size ResizedView
.
sourcefn max_width(self, max_width: usize) -> ResizedView<Self>
fn max_width(self, max_width: usize) -> ResizedView<Self>
Wraps self
into a limited-width ResizedView
.
sourcefn max_height(self, max_height: usize) -> ResizedView<Self>
fn max_height(self, max_height: usize) -> ResizedView<Self>
Wraps self
into a limited-height ResizedView
.
sourcefn min_size<S>(self, size: S) -> ResizedView<Self>where
S: Into<XY<usize>>,
fn min_size<S>(self, size: S) -> ResizedView<Self>where
S: Into<XY<usize>>,
Wraps self
into a ResizedView
at least sized size
.
sourcefn min_width(self, min_width: usize) -> ResizedView<Self>
fn min_width(self, min_width: usize) -> ResizedView<Self>
Wraps self
in a ResizedView
at least min_width
wide.
sourcefn min_height(self, min_height: usize) -> ResizedView<Self>
fn min_height(self, min_height: usize) -> ResizedView<Self>
Wraps self
in a ResizedView
at least min_height
tall.
sourceimpl<T> Scrollable for Twhere
T: View,
impl<T> Scrollable for Twhere
T: View,
sourcefn scrollable(self) -> ScrollView<Self>
fn scrollable(self) -> ScrollView<Self>
Wraps self
in a ScrollView
.