Skip to main content

text

Function text 

Source
pub fn text(
    p: &mut dyn Painter,
    bounds: Rect,
    style: &TextStyle,
    color: Color,
    msg: &str,
    truncate: Truncate,
) -> TextDrawn
Expand description

Draws a string of text within a rectangle.

The text is aligned horizontally according to style, wraps at the rectangle’s width, and is centered vertically when it fits (top-aligned when it doesn’t). If it is wider than the rectangle, truncate shortens it with an ellipsis (see fit_text). An empty string, or a rectangle with no width, draws nothing.

§Arguments

  • p - The painter, targeting the Widget.
  • bounds - The rectangle to draw within, in Widget coordinates.
  • style - The font and alignment.
  • color - The text color (overrides style.font_color, so a Widget can invert it).
  • msg - The text to draw.
  • truncate - How to shorten text that doesn’t fit.

§Returns

The size of the text drawn (0 by 0 if nothing was drawn) and whether it was shortened.