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

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

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

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"));

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);

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());

Returns the height.

Examples

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.