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 /// Where its left edge is.
11 pub x: f32,
12 /// Where its top edge is.
13 pub y: f32,
14 /// How far it reaches right of `x`.
15 pub width: f32,
16 /// How far it reaches down from `y`.
17 pub height: f32,
18}
19
20/// One glyph of a run: its id in its font and where its origin sits, in the
21/// run's coordinates.
22#[derive(Clone, Copy, Debug, PartialEq)]
23pub struct Glyph {
24 /// The glyph's id in its font.
25 pub id: u32,
26 /// Where its origin is across.
27 pub x: f32,
28 /// Where its origin is down: on the line's baseline.
29 pub y: f32,
30}
31
32/// What a `Draw::Fill` covers its path with.
33pub enum Paint {
34 /// One color, all over.
35 Solid(PColor),
36 /// A gradient whose points are in scene pixels.
37 Gradient(Gradient),
38 /// An image, placed by the transform from its pixels to scene pixels.
39 Image(ImageData, Affine),
40}
41
42/// One drawing command, in its chunk's coordinates: what both vello backends
43/// replay. Every decision about the drawing is made before a command is
44/// made; a backend only translates it into its library's call. The layers it
45/// is drawn in are nodes of the property trees, not commands.
46pub enum Draw {
47 /// A path filled with a paint.
48 Fill(BezPath, Paint),
49 /// A path's outline, stroked in one color, as wide in pixels as the `f32`
50 /// says.
51 Stroke(BezPath, f32, PColor),
52 /// A glyph run: its font, size and color, its point on the font's
53 /// variation axes — empty for a static font — and its glyphs.
54 Glyphs(FontData, f32, PColor, Vec<i16>, Vec<Glyph>),
55}