Skip to main content

Module paint

Module paint 

Source
Expand description

§Paint

The backend-neutral drawing API. A Widget draws by calling the Painter it is handed, never an SDL2 type, so widgets (and widget libraries) work with any backend. Reusable building blocks compose a Widget’s paint, all drawing into the Widget’s own surface:

  RootWidget   = fill
  BaseWidget   = fill
  BoxWidget    = fill + border
  TextWidget   = fill + text
  ButtonWidget = fill + text + border   (+ pressed state)

The pushrod-sdl2 crate’s Sdl2Painter is the default backend: each Widget paints into its own GPU texture only when invalidated, and frames are blits of cached textures. A backend declares its CachePolicy. The RecordingPainter records calls for unit tests, without a window.

Structs§

TextDrawn
The result of text.
TextStyle
The font and alignment used to draw text with text.

Enums§

CachePolicy
How a backend keeps painted Widgets between frames.
TextJustify
Horizontal alignment of text within its bounds.
Truncate
What text does with text that is wider than its rectangle.
Wrap
How paragraph breaks text into lines.

Constants§

ELLIPSIS
The ellipsis drawn where text is cut.

Traits§

Painter
The drawing operations a Widget’s paint can use. Kept small: only what the helpers in this module need.

Functions§

align_text
Computes where text of a given size is drawn within a rectangle.
border
Draws a border inside the edges of the surface.
fill
Fills the whole drawing surface with a color.
fit_text
Shortens text so it fits a width, cutting on grapheme boundaries and marking the cut with an ellipsis. The ellipsis is measured with the same measure function as the text, so the result never overflows max_width.
height_for_width
Measures the height of wrapped text for a given width, so a layout can give a label the height it needs.
paragraph
Draws wrapped text: a block of lines, each aligned by style.justification within the rectangle, centered vertically when the block fits (top-aligned when it doesn’t). Lines that start below the rectangle are not drawn.
state_overlay
Draws the generic look of a Widget’s visual state on top of what its paint drew.
text
Draws a string of text within a rectangle.
wrap_text
Breaks text into lines no wider than a width.