etui/widgets/paragraph

Types

Word-wrapping text block with alignment and styling.

pub type Paragraph {
  Paragraph(
    text: String,
    alignment: text.Alignment,
    fg: style.Color,
    bg: style.Color,
    modifier: style.Modifier,
  )
}

Constructors

Paragraph backed by styled span lines rather than a plain string. Use paragraph_new_lines to construct, render_lines_styled to render.

pub type SpanParagraph {
  SpanParagraph(lines: List(span.Line))
}

Constructors

Values

pub fn paragraph_new(text: String) -> Paragraph

New paragraph with left-aligned text and default colors.

pub fn paragraph_new_lines(
  lines: List(span.Line),
) -> SpanParagraph

Build a SpanParagraph from a list of span.Line values.

paragraph.paragraph_new_lines([
  span.line_new([span.span_plain("normal "), span.span_styled("bold", style.bold_style())]),
  span.line_plain("second line"),
])
|> paragraph.render_lines_styled(buf, area, _)
pub fn render(
  buf: buffer.Buffer,
  area: geometry.Rect,
  para: Paragraph,
) -> buffer.Buffer

Render paragraph into buffer at area. Word-wraps to area width. Rows beyond area height are clipped. Short lines are padded to area width.

pub fn render_lines_styled(
  buf: buffer.Buffer,
  area: geometry.Rect,
  para: SpanParagraph,
) -> buffer.Buffer

Render a SpanParagraph into area. Lines beyond area height are clipped. Does not wrap: see render_text for that.

pub fn render_styled(
  buf: buffer.Buffer,
  area: geometry.Rect,
  lines: List(span.Line),
) -> buffer.Buffer

Render a list of span.Line values, one per row, into area. Each Line is drawn with per-span styles. Lines beyond area height are clipped; the list may be shorter than the area (remaining rows unchanged).

pub fn render_text(
  buf: buffer.Buffer,
  area: geometry.Rect,
  content: span.Text,
) -> buffer.Buffer

Render styled text into area, wrapping it to the area width.

This is the one to reach for when text has both mixed styles and enough of it to need reflowing. render_styled puts one Line per row and lets anything too wide fall off the edge; paragraph_new wraps but only takes a plain String, so it cannot carry styles.

span.text_new([
  span.line_new([span.span_bold("ERROR"), span.span_plain(" disk full")]),
])
|> paragraph.render_text(buf, area, _)
pub fn with_alignment(
  p: Paragraph,
  alignment: text.Alignment,
) -> Paragraph

Set text alignment (Left, Center, Right).

pub fn with_style(p: Paragraph, s: style.Style) -> Paragraph

Apply a style (colors + modifier) to the paragraph text.

✨ Search Document