Struct ratatui::text::Line

source ·
pub struct Line<'a> {
    pub spans: Vec<Span<'a>>,
    pub alignment: Option<Alignment>,
}

Fields§

§spans: Vec<Span<'a>>§alignment: Option<Alignment>

Implementations§

source§

impl<'a> Line<'a>

source

pub fn width(&self) -> usize

Returns the width of the underlying string.

Examples
let line = Line::from(vec![
    Span::styled("My", Style::default().fg(Color::Yellow)),
    Span::raw(" text"),
]);
assert_eq!(7, line.width());
source

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

Patches the style of each Span in an existing Line, adding modifiers from the given style.

Examples
let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
let mut raw_line = Line::from(vec![
    Span::raw("My"),
    Span::raw(" text"),
]);
let mut styled_line = Line::from(vec![
    Span::styled("My", style),
    Span::styled(" text", style),
]);

assert_ne!(raw_line, styled_line);

raw_line.patch_style(style);
assert_eq!(raw_line, styled_line);
source

pub fn reset_style(&mut self)

Resets the style of each Span in the Line. Equivalent to calling patch_style(Style::reset()).

Examples
let mut line = Line::from(vec![
    Span::styled("My", Style::default().fg(Color::Yellow)),
    Span::styled(" text", Style::default().add_modifier(Modifier::BOLD)),
]);

line.reset_style();
assert_eq!(Style::reset(), line.spans[0].style);
assert_eq!(Style::reset(), line.spans[1].style);
source

pub fn alignment(self, alignment: Alignment) -> Self

Sets the target alignment for this line of text. Defaults to: None, meaning the alignment is determined by the rendering widget.

Examples
let mut line = Line::from("Hi, what's up?");
assert_eq!(None, line.alignment);
assert_eq!(Some(Alignment::Right), line.alignment(Alignment::Right).alignment)

Trait Implementations§

source§

impl<'a> Clone for Line<'a>

source§

fn clone(&self) -> Line<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Line<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Default for Line<'a>

source§

fn default() -> Line<'a>

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

impl<'a> From<&'a str> for Line<'a>

source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Line<'a>> for String

source§

fn from(line: Line<'a>) -> String

Converts to this type from the input type.
source§

impl<'a> From<Line<'a>> for Text<'a>

source§

fn from(line: Line<'a>) -> Text<'a>

Converts to this type from the input type.
source§

impl<'a> From<Span<'a>> for Line<'a>

source§

fn from(span: Span<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Spans<'a>> for Line<'a>

source§

fn from(value: Spans<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<String> for Line<'a>

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Vec<Span<'a>, Global>> for Line<'a>

source§

fn from(spans: Vec<Span<'a>>) -> Self

Converts to this type from the input type.
source§

impl<'a> PartialEq<Line<'a>> for Line<'a>

source§

fn eq(&self, other: &Line<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for Line<'a>

source§

impl<'a> StructuralEq for Line<'a>

source§

impl<'a> StructuralPartialEq for Line<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Line<'a>

§

impl<'a> Send for Line<'a>

§

impl<'a> Sync for Line<'a>

§

impl<'a> Unpin for Line<'a>

§

impl<'a> UnwindSafe for Line<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.