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§
Enums§
- Cache
Policy - How a backend keeps painted
Widgets between frames. - Text
Justify - Horizontal alignment of text within its bounds.
- Truncate
- What
textdoes with text that is wider than its rectangle. - Wrap
- How
paragraphbreaks text into lines.
Constants§
- ELLIPSIS
- The ellipsis drawn where text is cut.
Traits§
- Painter
- The drawing operations a
Widget’spaintcan 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
measurefunction as the text, so the result never overflowsmax_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.justificationwithin 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 itspaintdrew. - text
- Draws a string of text within a rectangle.
- wrap_
text - Breaks text into lines no wider than a width.