pub struct TextView { /* private fields */ }
Expand description
A simple view showing a fixed text.
Examples
let mut siv = Cursive::dummy();
siv.add_layer(TextView::new("Hello world!"));
Implementations
sourceimpl TextView
impl TextView
sourcepub fn new<S>(content: S) -> Selfwhere
S: Into<StyledString>,
pub fn new<S>(content: S) -> Selfwhere
S: Into<StyledString>,
Creates a new TextView with the given content.
sourcepub fn new_with_content(content: TextContent) -> Self
pub fn new_with_content(content: TextContent) -> Self
Creates a new TextView using the given Arc<Mutex<String>>
.
If you kept a clone of the given content, you’ll be able to update it remotely.
Examples
let mut content = TextContent::new("content");
let view = TextView::new_with_content(content.clone());
// Later, possibly in a different thread
content.set_content("new content");
assert!(content.get_content().source().contains("new"));
sourcepub fn set_effect(&mut self, effect: Effect)
pub fn set_effect(&mut self, effect: Effect)
Sets the effect for the entire content.
sourcepub fn effect(self, effect: Effect) -> Self
pub fn effect(self, effect: Effect) -> Self
Sets the effect for the entire content.
Chainable variant.
sourcepub fn no_wrap(self) -> Self
pub fn no_wrap(self) -> Self
Disables content wrap for this view.
This may be useful if you want horizontal scrolling.
sourcepub fn set_content_wrap(&mut self, wrap: bool)
pub fn set_content_wrap(&mut self, wrap: bool)
Controls content wrap for this view.
If true
(the default), text will wrap long lines when needed.
sourcepub fn content<S>(self, content: S) -> Selfwhere
S: Into<StyledString>,
pub fn content<S>(self, content: S) -> Selfwhere
S: Into<StyledString>,
Replace the text in this view.
Chainable variant.
sourcepub fn set_content<S>(&mut self, content: S)where
S: Into<StyledString>,
pub fn set_content<S>(&mut self, content: S)where
S: Into<StyledString>,
Replace the text in this view.
sourcepub fn append<S>(&mut self, content: S)where
S: Into<StyledString>,
pub fn append<S>(&mut self, content: S)where
S: Into<StyledString>,
Append content
to the end of a TextView
.
sourcepub fn get_content(&self) -> TextContentRef
pub fn get_content(&self) -> TextContentRef
Returns the current text in this view.
Returns a shared reference to the content, allowing content mutation.
Trait Implementations
sourceimpl View for TextView
impl View for TextView
sourcefn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Draws the view with the given printer (includes bounds) and focus. Read more
sourcefn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
Returns
true
if the view content changed since last layout phase. Read moresourcefn required_size(&mut self, size: Vec2) -> Vec2
fn required_size(&mut self, size: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions. Read more
sourcefn layout(&mut self, size: Vec2)
fn layout(&mut self, size: Vec2)
Called once the size for this view has been decided. Read more
sourcefn on_event(&mut self, : Event) -> EventResult
fn on_event(&mut self, : Event) -> EventResult
Called when an event is received (key press, mouse event, …). Read more
sourcefn call_on_any<'a>(&mut self, _: &Selector<'_>, _: AnyCb<'a>)
fn call_on_any<'a>(&mut self, _: &Selector<'_>, _: AnyCb<'a>)
Runs a closure on the view identified by the given selector. Read more
sourcefn focus_view(&mut self, : &Selector<'_>) -> Result<(), ()>
fn focus_view(&mut self, : &Selector<'_>) -> Result<(), ()>
Moves the focus to the view identified by the given selector. Read more
sourcefn take_focus(&mut self, source: Direction) -> bool
fn take_focus(&mut self, source: Direction) -> bool
This view is offered focus. Will it take it? Read more
sourcefn important_area(&self, view_size: Vec2) -> Rect
fn important_area(&self, view_size: Vec2) -> Rect
What part of the view is important and should be visible? Read more
Auto Trait Implementations
impl RefUnwindSafe for TextView
impl Send for TextView
impl Sync for TextView
impl Unpin for TextView
impl UnwindSafe for TextView
Blanket Implementations
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