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§
- Color
Brush - The brush carried through a text layout.
- Text
- A reusable piece of styled text with a cached layout.
- Text
Context - The system font database plus Parley’s shaping and layout caches.
- Text
Style - 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§
- Text
Layout - A Parley layout specialised to crownshell’s brush type.