title

Styled title atom with optional truncation and column padding.

struct Component

source

pub struct Component

A styled heading with optional truncation and padding.

Field Type Description
max_width Option<usize> Display width above which the text is cut to max_width - 1 characters plus …; None never cuts.
pad_to Option<usize> Minimum visible width, filled with trailing spaces; None never pads.
style Style Style painted over the text.
text String Title text.

Implements Display.

Component::new

source

pub fn new(text: impl Into<String>, style: Style) -> Self

Create a new title with the given text and style.

Parameter Type Description
text impl Into<String> the title text
style Style the style to paint it in
returns Self The title, with no truncation or padding.

Component::max_width

source

pub fn max_width(self, width: usize) -> Self

Truncate the title to at most width visible characters, appending … if needed.

Parameter Type Description
width usize the display width above which the title is cut to width - 1 characters plus …; wide characters can still exceed it
returns Self The title with the limit set.

Component::pad_to

source

pub fn pad_to(self, width: usize) -> Self

Right-pad with spaces so the title occupies at least width visible columns.

Parameter Type Description
width usize the minimum visible width
returns Self The title with the padding set.