Skip to main content

Module text

Module text 

Source
Expand description

Text layout and rendering, powered by Parley and drawn through Vello.

TextContext holds the system font database and Parley’s layout scratch space. It is created once per process and handed to SurfaceHandler calls through SurfaceCtx::text.

Text is a retained, reusable piece of text: set its content and style, measure it, and draw it. The underlying Parley layout is cached and only rebuilt when the content, style or scale actually changes, which matters because crownshell only repaints on demand.

use crownshell::predule::*;

struct Bar {
    clock: Text,
}

impl SurfaceHandler for Bar {
    fn paint(&mut self, scene: &mut Scene, ctx: SurfaceCtx<'_>) {
        self.clock.set_text("12:45");
        let size = self.clock.size(ctx.text);
        let x = (ctx.size.0 as f64 - size.width) / 2.0;
        self.clock.draw(ctx.text, scene, (x, 8.0));
    }
}

Structs§

ColorBrush
The brush carried through a text layout.
Text
A reusable piece of styled text with a cached layout.
TextContext
The system font database plus Parley’s shaping and layout caches.
TextStyle
Visual properties applied to a whole Text.

Functions§

draw_layout
Encodes an already-built Parley layout into a Vello scene under transform, which maps the layout’s own coordinate space into the scene’s.

Type Aliases§

TextLayout
A Parley layout specialised to crownshell’s brush type.