Text

Struct Text 

Source
pub struct Text {
    pub spans: Vec<Span>,
    pub alignment: Alignment,
    pub overflow: Overflow,
    pub style: Style,
}
Expand description

A text container with multiple styled spans.

Fields§

§spans: Vec<Span>

The spans that make up this text

§alignment: Alignment

Text alignment

§overflow: Overflow

Overflow behavior

§style: Style

Optional style applied to the whole text

Implementations§

Source§

impl Text

Source

pub fn new() -> Self

Create a new empty text.

Source

pub fn plain<S: Into<Cow<'static, str>>>(text: S) -> Self

Create text from a plain string.

Source

pub fn styled<S: Into<Cow<'static, str>>>(text: S, style: Style) -> Self

Create text from a styled string.

Source

pub fn from_spans<I: IntoIterator<Item = Span>>(spans: I) -> Self

Create text from multiple spans.

Source

pub fn push_span(&mut self, span: Span)

Add a span to the text.

Source

pub fn push<S: Into<Cow<'static, str>>>(&mut self, text: S)

Append plain text.

Source

pub fn push_styled<S: Into<Cow<'static, str>>>(&mut self, text: S, style: Style)

Append styled text.

Source

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

Set the alignment.

Source

pub fn overflow(self, overflow: Overflow) -> Self

Set the overflow behavior.

Source

pub fn style(self, style: Style) -> Self

Set the overall style.

Source

pub fn width(&self) -> usize

Get the total display width (without line breaks).

Source

pub fn plain_text(&self) -> String

Get the plain text content without styling.

Source

pub fn is_empty(&self) -> bool

Check if the text is empty.

Source

pub fn wrap(&self, width: usize) -> Vec<Vec<Span>>

Split the text into lines, wrapping at the given width.

Source

pub fn align_line(&self, line: Vec<Span>, width: usize) -> Vec<Span>

Apply alignment to a line, returning padded spans.

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

Returns a duplicate 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 Debug for Text

Source§

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

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

impl Default for Text

Source§

fn default() -> Text

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

impl<S: Into<Cow<'static, str>>> From<S> for Text

Source§

fn from(text: S) -> Self

Converts to this type from the input type.
Source§

impl Renderable for Text

Implement Renderable for Text.

Source§

fn render(&self, context: &RenderContext) -> Vec<Segment>

Render this object to a sequence of segments. Read more
Source§

fn min_width(&self) -> usize

Get the minimum width required to render this object.
Source§

fn max_width(&self) -> usize

Get the maximum/natural width of this object.

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnwindSafe for Text

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> Measurable for T
where T: Renderable,

Source§

fn measure(&self, width: usize) -> Measurement

Measure this renderable at the given width.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.