pub struct Paragraph<'a> { /* private fields */ }Expand description
Word-wrapped text in a single Style.
Paragraph::new(text) wraps text to whatever width it is rendered at
(via Widget::render), or reports the height it would need at a
given width without rendering (via Measure::height_for) so a caller
can size its pane to fit instead of guessing a fixed height. style
defaults to Style::new(); set it with Paragraph::style.
Without the egc feature, wrapping is char-boundary-safe and breaks
on ASCII whitespace only: no grapheme-cluster segmentation, so a
combining mark or wide CJK run can land on either side of a wrap point.
Enabling egc upgrades wrapping to retroglyph_core::layout::TextLayout,
which is grapheme-cluster-aware; every other text-bearing widget in this
crate (List, Table, Log) already has this same gap regardless of
egc.
Unlike super::BoxBorder, super::Gauge, super::StatBar,
super::Table, and super::Button, Paragraph has no theme()/
theme_on() pair: word-wrapped text has no single semantic
Theme role to map onto, so callers set style directly.
§Examples
use retroglyph_core::grid::{Grid, Rect};
use retroglyph_ui::widget::{Measure, Paragraph, Widget};
use retroglyph_ui::Surface;
let p = Paragraph::new("the quick brown fox jumps");
let height = p.height_for(10); // rows needed to wrap at 10 columns
let area = Rect::new(0, 0, 10, height);
let mut grid = Grid::new(10, height);
p.render(&mut Surface::new(&mut grid, area, 0));