pub struct Paragraph { /* private fields */ }Expand description
A widget combining multiple widgets implementing the Text trait into
single widget.
A Paragraph combines multiple widgets implementing the Text trait
into single widget, displaying them sequantially with configurable
separator.
Unlike layout-based widgets, Paragraph places spans directly next to
each other, allowing for more natural inline text composition.
§Example
// Creates a Paragraph from a list of spans
let items: Vec<Box<dyn Text>> = vec![
Box::new("This is a text in".fg(Color::Yellow)),
Box::new("paragraph".modifier(Modifier::BOLD).fg(Color::Cyan)),
Box::new("and it adds".to_span()),
Box::new("separator".modifier(Modifier::ITALIC)),
];
let mut p = Paragraph::new(items)
.wrap(Wrap::Letter)
.separator("-");
// Alternatively, use the `paragraph!` macro for convenience
let mut p = paragraph!(
"This is a text in".fg(Color::Yellow),
"paragraph".modifier(Modifier::BOLD).fg(Color::Cyan),
"and it adds".to_span(),
"separator".modifier(Modifier::ITALIC),
);
// Add more text later if needed
p.push("between each span");
// Print the Paragraph as a string
println!("{p}");
// Or you can render it using `Term` (or manually using `Buffer`)
let mut term = Term::default();
term.render(p)?;Implementations§
Source§impl Paragraph
impl Paragraph
Sourcepub fn new(children: Vec<Box<dyn Text>>) -> Self
pub fn new(children: Vec<Box<dyn Text>>) -> Self
Creates a new Paragraph with the given child elements.
Sourcepub fn separator(self, sep: &str) -> Self
pub fn separator(self, sep: &str) -> Self
Sets the separator used between child elements when rendering the
Paragraph.
Sourcepub fn wrap(self, wrap: Wrap) -> Self
pub fn wrap(self, wrap: Wrap) -> Self
Sets text wrapping style of the Paragraph.
Default value is Wrap::Word.
Trait Implementations§
Source§impl Widget for Paragraph
impl Widget for Paragraph
Source§fn height(&self, size: &Vec2) -> usize
fn height(&self, size: &Vec2) -> usize
Returns the height of the
Widget based on the width of the given
size.Auto Trait Implementations§
impl Freeze for Paragraph
impl !RefUnwindSafe for Paragraph
impl !Send for Paragraph
impl !Sync for Paragraph
impl Unpin for Paragraph
impl !UnwindSafe for Paragraph
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> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more