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::{Measure, Paragraph, Surface, Widget};
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));Implementations§
Trait Implementations§
Source§impl Measure for Paragraph<'_>
Available on crate feature egc only.
impl Measure for Paragraph<'_>
egc only.Source§fn height_for(&self, width: u16) -> u16
fn height_for(&self, width: u16) -> u16
width
columns.impl<'a> Copy for Paragraph<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).