Struct tui::text::Text[][src]

pub struct Text<'a> {
    pub lines: Vec<Spans<'a>>,
}

A string split over multiple lines where each line is composed of several clusters, each with their own style.

A Text, like a Span, can be constructed using one of the many From implementations or via the Text::raw and Text::styled methods. Helpfully, Text also implements core::iter::Extend which enables the concatenation of several Text blocks.

let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);

// An initial two lines of `Text` built from a `&str`
let mut text = Text::from("The first line\nThe second line");
assert_eq!(2, text.height());

// Adding two more unstyled lines
text.extend(Text::raw("These are two\nmore lines!"));
assert_eq!(4, text.height());

// Adding a final two styled lines
text.extend(Text::styled("Some more lines\nnow with more style!", style));
assert_eq!(6, text.height());

Fields

lines: Vec<Spans<'a>>

Implementations

impl<'a> Text<'a>[src]

pub fn raw<T>(content: T) -> Text<'a> where
    T: Into<Cow<'a, str>>, 
[src]

Create some text (potentially multiple lines) with no style.

Examples

Text::raw("The first line\nThe second line");
Text::raw(String::from("The first line\nThe second line"));

pub fn styled<T>(content: T, style: Style) -> Text<'a> where
    T: Into<Cow<'a, str>>, 
[src]

Create some text (potentially multiple lines) with a style.

Examples

let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
Text::styled("The first line\nThe second line", style);
Text::styled(String::from("The first line\nThe second line"), style);

pub fn width(&self) -> usize[src]

Returns the max width of all the lines.

Examples

use tui::text::Text;
let text = Text::from("The first line\nThe second line");
assert_eq!(15, text.width());

pub fn height(&self) -> usize[src]

Returns the height.

Examples

use tui::text::Text;
let text = Text::from("The first line\nThe second line");
assert_eq!(2, text.height());

pub fn patch_style(&mut self, style: Style)[src]

Apply a new style to existing text.

Examples

let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
let mut raw_text = Text::raw("The first line\nThe second line");
let styled_text = Text::styled(String::from("The first line\nThe second line"), style);
assert_ne!(raw_text, styled_text);

raw_text.patch_style(style);
assert_eq!(raw_text, styled_text);

Trait Implementations

impl<'a> Clone for Text<'a>[src]

impl<'a> Debug for Text<'a>[src]

impl<'a> Default for Text<'a>[src]

impl<'a> Extend<Spans<'a>> for Text<'a>[src]

impl<'a> From<&'a str> for Text<'a>[src]

impl<'a> From<Span<'a>> for Text<'a>[src]

impl<'a> From<Spans<'a>> for Text<'a>[src]

impl<'a> From<String> for Text<'a>[src]

impl<'a> From<Vec<Spans<'a>, Global>> for Text<'a>[src]

impl<'a> IntoIterator for Text<'a>[src]

type Item = Spans<'a>

The type of the elements being iterated over.

type IntoIter = IntoIter<Self::Item>

Which kind of iterator are we turning this into?

impl<'a> PartialEq<Text<'a>> for Text<'a>[src]

impl<'a> StructuralPartialEq for Text<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Text<'a>

impl<'a> Send for Text<'a>

impl<'a> Sync for Text<'a>

impl<'a> Unpin for Text<'a>

impl<'a> UnwindSafe for Text<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.