pub struct Paragraph<'a> { /* private fields */ }Expand description
A widget to display some text.
§Examples
let text = vec![
Spans::from(vec![
Span::raw("First"),
Span::styled("line",Style::default().add_modifier(Modifier::ITALIC)),
Span::raw("."),
]),
Spans::from(Span::styled("Second line", Style::default().fg(Color::Red))),
];
let mut paragraph = Paragraph::new(text);
paragraph.block(Block::default().title("Paragraph").borders(Borders::ALL));
paragraph.style(Style::default().fg(Color::White).bg(Color::Black));
paragraph.alignment(Alignment::Center);
paragraph.wrap(Wrap { trim: true });Implementations§
Source§impl<'a> Paragraph<'a>
impl<'a> Paragraph<'a>
pub fn new<T>(text: T) -> Paragraph<'a>
pub fn text<T>(&mut self, text: T)
pub fn block(&mut self, block: Block<'a>)
Sourcepub fn scrollbar(&mut self, scrollbar: Scrollbar<'a>)
pub fn scrollbar(&mut self, scrollbar: Scrollbar<'a>)
Attach a scrollbar to the paragraph
Adds a scrollbar that visually indicates the current scroll position and allows users to understand the relative position within the content.
§See Also
Paragraph::content_height- Get total lines for vertical scrollingParagraph::content_width- Get max width for horizontal scrollingParagraph::scroll- Set scroll position
pub fn text_style(&mut self, style: Style)
pub fn style(&mut self, style: Style)
pub fn wrap(&mut self, wrap: Wrap)
pub fn margin(&mut self, margin: u16)
pub fn horizontal_margin(&mut self, horizontal: u16)
pub fn vertical_margin(&mut self, vertical: u16)
Sourcepub fn scroll(&mut self, offset: (u16, u16))
pub fn scroll(&mut self, offset: (u16, u16))
Sets Y and X axis offsets accordingly
§Note
The scroll position will be automatically clamped during rendering to ensure it doesn’t exceed valid bounds:
- Vertical scroll will be limited to
max(0, content_height - viewport_height) - Horizontal scroll will be limited to
max(0, content_width - viewport_width)
Content dimensions (content_height and content_width) are calculated
during the first render after text changes. To get actual content dimensions:
- After setting new text, call
render()at least once - Then use
Paragraph::content_heightandParagraph::content_widthmethods
pub fn alignment(&mut self, alignment: Alignment)
Sourcepub fn content_height(&self) -> Option<u16>
pub fn content_height(&self) -> Option<u16>
Returns Some(content height) if vertical scrollbar was set or None
Sourcepub fn content_width(&self) -> Option<u16>
pub fn content_width(&self) -> Option<u16>
Returns Some(content width) if horizontal scrollbar was set or None
This is the width of the longest line in the text.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Paragraph<'a>
impl<'a> RefUnwindSafe for Paragraph<'a>
impl<'a> Send for Paragraph<'a>
impl<'a> Sync for Paragraph<'a>
impl<'a> Unpin for Paragraph<'a>
impl<'a> UnsafeUnpin for Paragraph<'a>
impl<'a> UnwindSafe for Paragraph<'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