Skip to main content

Paragraph

Struct Paragraph 

Source
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>

Source

pub fn new<T>(text: T) -> Paragraph<'a>
where T: Into<Text<'a>>,

Source

pub fn text<T>(&mut self, text: T)
where T: Into<Text<'a>>,

Source

pub fn block(&mut self, block: Block<'a>)

Source

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
Source

pub fn text_style(&mut self, style: Style)

Source

pub fn style(&mut self, style: Style)

Source

pub fn wrap(&mut self, wrap: Wrap)

Source

pub fn margin(&mut self, margin: u16)

Source

pub fn horizontal_margin(&mut self, horizontal: u16)

Source

pub fn vertical_margin(&mut self, vertical: u16)

Source

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:

  1. After setting new text, call render() at least once
  2. Then use Paragraph::content_height and Paragraph::content_width methods
Source

pub fn alignment(&mut self, alignment: Alignment)

Source

pub fn content_height(&self) -> Option<u16>

Returns Some(content height) if vertical scrollbar was set or None

Source

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§

Source§

impl<'a> Clone for Paragraph<'a>

Source§

fn clone(&self) -> Paragraph<'a>

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<'a> Debug for Paragraph<'a>

Source§

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

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

impl<'a> Widget for Paragraph<'a>

Source§

fn render(&mut self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more