devpage_design/display/draw.rs
1//! What a display list is made of: the drawing commands both paint
2//! backends replay, and the boxes layout gives the nodes they draw.
3
4use kurbo::{Affine, BezPath};
5use peniko::{Color as PColor, FontData, Gradient, ImageData};
6
7/// A node's box after layout, in the scene's pixels.
8#[derive(Debug, Clone, Copy, PartialEq)]
9pub struct Frame {
10 pub x: f32,
11 pub y: f32,
12 pub width: f32,
13 pub height: f32,
14}
15
16/// One glyph of a run: its id in its font and where its origin sits, in the
17/// run's coordinates.
18#[derive(Clone, Copy, Debug, PartialEq)]
19pub struct Glyph {
20 pub id: u32,
21 pub x: f32,
22 pub y: f32,
23}
24
25/// What a `Draw::Fill` covers its path with.
26pub enum Paint {
27 Solid(PColor),
28 /// A gradient whose points are in scene pixels.
29 Gradient(Gradient),
30 /// An image, placed by the transform from its pixels to scene pixels.
31 Image(ImageData, Affine),
32}
33
34/// One drawing command, in its chunk's coordinates: what both vello backends
35/// replay. Every decision about the drawing is made before a command is
36/// made; a backend only translates it into its library's call. The layers it
37/// is drawn in are nodes of the property trees, not commands.
38pub enum Draw {
39 Fill(BezPath, Paint),
40 Stroke(BezPath, f32, PColor),
41 /// A glyph run: its font, size and color, its point on the font's
42 /// variation axes — empty for a static font — and its glyphs.
43 Glyphs(FontData, f32, PColor, Vec<i16>, Vec<Glyph>),
44}