[−][src]Struct cursive::views::EditView
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_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
impl EditView
[src]
pub fn disable(&mut self)
[src]
Disables this view.
A disabled view cannot be selected.
pub fn disabled(self) -> EditView
[src]
Disables this view.
Chainable variant.
pub fn enable(&mut self)
[src]
Re-enables this view.
pub fn set_enabled(&mut self, enabled: bool)
[src]
Enable or disable this view.
pub fn with_enabled(self, is_enabled: bool) -> EditView
[src]
Enable or disable this view.
Chainable variant.
pub fn is_enabled(&self) -> bool
[src]
Returns true
if this view is enabled.
pub fn new() -> EditView
[src]
Creates a new, empty edit view.
pub fn set_max_content_width(&mut self, width: Option<usize>)
[src]
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) -> EditView
[src]
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]
If secret
is true
, the content won't be displayed in clear.
Only *
will be shown.
pub fn secret(self) -> EditView
[src]
Hides the content of the view.
Only *
will be shown.
pub fn set_filler<S>(&mut self, filler: S) where
S: Into<String>,
[src]
S: Into<String>,
Sets the character to fill in blank space.
Defaults to "_".
pub fn filler<S>(self, filler: S) -> EditView where
S: Into<String>,
[src]
S: Into<String>,
Sets the character to fill in blank space.
Chainable variant.
Examples
let edit = EditView::new().filler(" ");
pub fn set_style(&mut self, style: ColorStyle)
[src]
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) -> EditView
[src]
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]
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]
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) -> EditView where
F: FnMut(&mut Cursive, &str, usize) + 'static,
[src]
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) -> EditView where
F: Fn(&mut Cursive, &str, usize) + 'static,
[src]
F: Fn(&mut Cursive, &str, usize) + 'static,
Sets a callback to be called whenever the content is modified.
Chainable variant. See set_on_edit
.
Examples
use cursive_core::views::{TextContent, TextView, EditView}; // 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: FnMut(&mut Cursive, &str) + 'static,
[src]
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]
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) -> EditView where
F: FnMut(&mut Cursive, &str) + 'static,
[src]
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) -> EditView where
F: Fn(&mut Cursive, &str) + 'static,
[src]
F: Fn(&mut Cursive, &str) + 'static,
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)); });
pub fn set_content<S>(&mut self, content: S) -> Callback where
S: Into<String>,
[src]
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
.
pub fn get_content(&self) -> Rc<String>
[src]
Get the current text.
pub fn content<S>(self, content: S) -> EditView where
S: Into<String>,
[src]
S: Into<String>,
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]
Sets the cursor position.
pub fn insert(&mut self, ch: char) -> Callback
[src]
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]
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 View for EditView
[src]
fn draw(&self, printer: &Printer)
[src]
fn layout(&mut self, size: XY<usize>)
[src]
fn take_focus(&mut self, Direction) -> bool
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn important_area(&self, XY<usize>) -> Rect
[src]
fn needs_relayout(&self) -> bool
[src]
fn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
[src]
fn call_on_any(
&mut self,
&Selector,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
&Selector,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
fn focus_view(&mut self, &Selector) -> Result<(), ()>
[src]
fn type_name(&self) -> &'static str
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AnyView for T where
T: View,
[src]
T: View,
fn as_any(&self) -> &(dyn Any + 'static)
[src]
Downcast self to a Any
.
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
Downcast self to a mutable Any
.
fn as_boxed_any(self: Box<T>) -> Box<dyn Any + 'static>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> Finder for T where
T: View,
[src]
T: View,
fn call_on<V, F, R>(&mut self, sel: &Selector, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
fn find_name<V>(
&mut self,
name: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
[src]
&mut self,
name: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
fn find_id<V>(
&mut self,
id: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
[src]
&mut self,
id: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoBoxedView for T where
T: View,
[src]
T: View,
fn as_boxed_view(self) -> Box<dyn View + 'static>
[src]
impl<T> Nameable for T where
T: View,
[src]
T: View,
fn with_name<S>(self, name: S) -> NamedView<Self> where
S: Into<String>,
[src]
S: Into<String>,
fn with_id<S>(self, id: S) -> NamedView<Self> where
S: Into<String>,
[src]
S: Into<String>,
impl<T> Resizable for T where
T: View,
[src]
T: View,
fn boxed(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
[src]
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
fn resized(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
[src]
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
fn fixed_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
fn fixed_width(self, width: usize) -> ResizedView<Self>
[src]
fn fixed_height(self, height: usize) -> ResizedView<Self>
[src]
fn full_screen(self) -> ResizedView<Self>
[src]
fn full_width(self) -> ResizedView<Self>
[src]
fn full_height(self) -> ResizedView<Self>
[src]
fn max_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
fn max_width(self, max_width: usize) -> ResizedView<Self>
[src]
fn max_height(self, max_height: usize) -> ResizedView<Self>
[src]
fn min_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
fn min_width(self, min_width: usize) -> ResizedView<Self>
[src]
fn min_height(self, min_height: usize) -> ResizedView<Self>
[src]
impl<T> Scrollable for T where
T: View,
[src]
T: View,
fn scrollable(self) -> ScrollView<Self>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> View for T where
T: ViewWrapper,
[src]
T: ViewWrapper,
fn draw(&self, printer: &Printer)
[src]
fn required_size(&mut self, req: XY<usize>) -> XY<usize>
[src]
fn on_event(&mut self, ch: Event) -> EventResult
[src]
fn layout(&mut self, size: XY<usize>)
[src]
fn take_focus(&mut self, source: Direction) -> bool
[src]
fn call_on_any(
&mut self,
selector: &Selector,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)