Expand description
Word wrapping that answers a height and a drawing from the same measurement.
The half ratatui’s Paragraph leaves out. A flow layout asks for rows at a
width and then draws into the rect it was given, and if the two disagree by
one row a node draws over the one under it.
Words into cells.
A terminal wraps on words and counts rows, and both halves have to agree or
a node draws over the one under it. So the wrap is written once here and
both [height] and [draw] read it, rather than each having its own idea
of how many rows a paragraph takes.
Arrived here from quasi-tui in 0.16.0, which is where it was written and
where it stopped being quasi’s: nothing below is about a described screen.
Flow layout is the shape every terminal consumer in the tree ends up with —
ask for a height at a width, then draw into the rect you were given — and it
needs a wrap that answers both questions the same way. ratatui’s own
Paragraph wraps but will not tell you how many rows it took, which is the
half a flow layout cannot do without.
Width is counted in chars. That is wrong for a terminal in the general
case – a CJK glyph occupies two cells and a combining mark none – and it
is deliberately not fixed here: the fix is a unicode-width dependency, and
taking one before anything in the tree has non-ASCII content to draw is
paying for a problem nobody has yet. Filed rather than hidden.
Functions§
- draw
- Draw wrapped text at the top of
area, and answer the rows it used. - draw_
line - Draw a line of spans at the top of
area, wrapping onto further rows. - draw_
spans - Draw wrapped spans at the top of
area, and answer the rows they used. - height
- The rows
texttakes atwidth. - line_
height - The rows a line of spans takes at
width. - spans_
height - The rows
spanstake atwidth, wrapped as a block. - wrap
- Break
textinto lines no wider thanwidth. - wrap_
spans - Break
spansinto lines no wider thanwidth, keeping each word under the style it arrived with.