pub struct Text<'a> { /* private fields */ }Expand description
A collection of styled text spans.
Text provides a high-level interface for working with styled text.
It stores spans (styled text units) and provides operations for:
- Appending and building text
- Applying base styles
- Splitting into lines
- Truncating and wrapping to widths
§Ownership
Text supports borrowing via Cow in Span. Use Text<'a> to hold
references, or Text<'static> (or just Text if aliased) for owned data.
Implementations§
Source§impl<'a> Text<'a>
impl<'a> Text<'a>
Sourcepub fn raw(content: impl Into<Cow<'a, str>>) -> Self
pub fn raw(content: impl Into<Cow<'a, str>>) -> Self
Create text from a raw string (may contain newlines).
Sourcepub fn styled(content: impl Into<Cow<'a, str>>, style: Style) -> Self
pub fn styled(content: impl Into<Cow<'a, str>>, style: Style) -> Self
Create styled text from a string (may contain newlines).
Sourcepub fn from_lines(lines: impl IntoIterator<Item = Line<'a>>) -> Self
pub fn from_lines(lines: impl IntoIterator<Item = Line<'a>>) -> Self
Create text from multiple lines.
Sourcepub fn from_spans(spans: impl IntoIterator<Item = Span<'a>>) -> Self
pub fn from_spans(spans: impl IntoIterator<Item = Span<'a>>) -> Self
Create text from spans (single line).
Sourcepub fn from_segments(segments: impl IntoIterator<Item = Segment<'a>>) -> Self
pub fn from_segments(segments: impl IntoIterator<Item = Segment<'a>>) -> Self
Create text from segments.
Sourcepub fn height_as_u16(&self) -> u16
pub fn height_as_u16(&self) -> u16
Get the number of lines as u16, saturating at u16::MAX.
Sourcepub fn measurement(&self) -> TextMeasurement
pub fn measurement(&self) -> TextMeasurement
Return bounds-based measurement for this text block.
Sourcepub fn style(&self) -> Option<Style>
pub fn style(&self) -> Option<Style>
Get the style of the first span, if any.
Returns None if the text is empty or has no styled spans.
Sourcepub fn push_span(&mut self, span: Span<'a>)
pub fn push_span(&mut self, span: Span<'a>)
Add a span to the last line (or create new line if empty).
Sourcepub fn with_span(self, span: Span<'a>) -> Self
pub fn with_span(self, span: Span<'a>) -> Self
Append a span to the last line (builder pattern).
Sourcepub fn apply_base_style(&mut self, base: Style)
pub fn apply_base_style(&mut self, base: Style)
Apply a base style to all lines and spans.
The base style is merged with each span’s style, with the span’s style taking precedence for conflicting properties.
Sourcepub fn with_base_style(self, base: Style) -> Self
pub fn with_base_style(self, base: Style) -> Self
Create a new Text with base style applied.
Sourcepub fn to_plain_text(&self) -> String
pub fn to_plain_text(&self) -> String
Get the plain text content (lines joined with newlines).
Sourcepub fn into_segment_lines(self) -> SegmentLines<'a>
pub fn into_segment_lines(self) -> SegmentLines<'a>
Convert to SegmentLines.
Trait Implementations§
Source§impl<'a> FromIterator<Line<'a>> for Text<'a>
impl<'a> FromIterator<Line<'a>> for Text<'a>
Source§impl<'a> FromIterator<Span<'a>> for Text<'a>
impl<'a> FromIterator<Span<'a>> for Text<'a>
Source§impl<'a> IntoIterator for &'a Text<'a>
impl<'a> IntoIterator for &'a Text<'a>
Source§impl<'a> IntoIterator for Text<'a>
impl<'a> IntoIterator for Text<'a>
impl<'a> Eq for Text<'a>
impl<'a> StructuralPartialEq for Text<'a>
Auto Trait Implementations§
impl<'a> Freeze for Text<'a>
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> UnsafeUnpin for Text<'a>
impl<'a> UnwindSafe for Text<'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
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
key and return true if they are equal.