pub struct Line<'a> {
pub spans: Vec<Span<'a>>,
pub alignment: Alignment,
pub style: Style,
}Expand description
A line of text composed of multiple styled spans.
A line represents a single row of text that can have multiple different styles.
§Example
use tuxtui_core::text::{Line, Span};
use tuxtui_core::style::{Color, Style};
let line = Line::from(vec![
Span::styled("Hello ", Style::default().fg(Color::Blue)),
Span::styled("World!", Style::default().fg(Color::Red)),
]);Fields§
§spans: Vec<Span<'a>>The spans that make up this line
alignment: AlignmentAlignment for this line
style: StyleLine style applied to all spans
Implementations§
Source§impl<'a> Line<'a>
impl<'a> Line<'a>
Sourcepub fn from_spans(spans: Vec<Span<'a>>) -> Self
pub fn from_spans(spans: Vec<Span<'a>>) -> Self
Create a new line from spans.
Sourcepub fn styled<T: Into<Cow<'a, str>>>(content: T, style: Style) -> Self
pub fn styled<T: Into<Cow<'a, str>>>(content: T, style: Style) -> Self
Create a styled line from a string.
Sourcepub fn truncate(self, max_width: usize, ellipsis: Option<&str>) -> Line<'a>
pub fn truncate(self, max_width: usize, ellipsis: Option<&str>) -> Line<'a>
Truncate the line to fit within the given width, optionally adding an ellipsis.
§Example
use tuxtui_core::text::Line;
let line = Line::from("This is a very long line");
let truncated = line.truncate(10, Some("..."));
assert!(truncated.width() <= 10);Sourcepub fn into_owned(self) -> Line<'static>
pub fn into_owned(self) -> Line<'static>
Convert this line to an owned version.
Sourcepub fn patch_style(self, style: Style) -> Self
pub fn patch_style(self, style: Style) -> Self
Patch the style of this line (affects all spans).
Trait Implementations§
Source§impl<'de, 'a> Deserialize<'de> for Line<'a>
impl<'de, 'a> Deserialize<'de> for Line<'a>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a> Stylize for Line<'a>
impl<'a> Stylize for Line<'a>
Source§fn underlined(self) -> Self
fn underlined(self) -> Self
Make the text underlined.
Source§fn slow_blink(self) -> Self
fn slow_blink(self) -> Self
Make the text blink slowly.
Source§fn rapid_blink(self) -> Self
fn rapid_blink(self) -> Self
Make the text blink rapidly.
Make the text hidden.
Source§fn crossed_out(self) -> Self
fn crossed_out(self) -> Self
Make the text crossed out.
impl<'a> Eq for Line<'a>
impl<'a> StructuralPartialEq for Line<'a>
Auto Trait Implementations§
impl<'a> Freeze for Line<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.