Skip to main content

euv_chart/display/
enum.rs

1use super::*;
2
3/// A single drawing instruction in the display list.
4///
5/// The display list is the boundary between the chart model and the
6/// rendering backends: the model produces it, and every backend knows how
7/// to replay it. Nothing above this layer mentions WebGPU, WebGL, or
8/// Canvas2D, which is what lets a single API serve all three.
9#[derive(Clone, Debug, Default)]
10pub enum DrawCmd {
11    /// Fills a path.
12    Fill {
13        /// The path to fill.
14        path: Path,
15        /// The fill paint.
16        paint: Fill,
17        /// The overall opacity applied to the fill, from `0.0` to `1.0`.
18        opacity: f64,
19    },
20    /// Strokes a path.
21    Stroke {
22        /// The path to stroke.
23        path: Path,
24        /// The stroke paint.
25        paint: Stroke,
26        /// The geometry of the stroke.
27        style: LineStyle,
28        /// The overall opacity applied to the stroke, from `0.0` to `1.0`.
29        opacity: f64,
30    },
31    /// Draws a text run.
32    Text {
33        /// The text to draw.
34        text: String,
35        /// The horizontal anchor of the text, in canvas pixels.
36        x: f64,
37        /// The vertical anchor of the text, in canvas pixels.
38        y: f64,
39        /// The style of the text.
40        style: TextStyle,
41    },
42    /// Draws an image.
43    Image {
44        /// The image element to draw.
45        image: HtmlImageElement,
46        /// The horizontal position of the image, in canvas pixels.
47        x: f64,
48        /// The vertical position of the image, in canvas pixels.
49        y: f64,
50        /// The width of the image, in canvas pixels.
51        width: f64,
52        /// The height of the image, in canvas pixels.
53        height: f64,
54    },
55    /// Intersects the clip region with a path.
56    Clip {
57        /// The path to clip against.
58        path: Path,
59    },
60    /// Restores the clip region that was in effect before the matching
61    /// [`DrawCmd::Clip`].
62    #[default]
63    PopClip,
64    /// Draws a filled triangle strip, the shape of an area chart.
65    ///
66    /// The strip is a first-class instruction rather than a path so the
67    /// GPU backends can emit it without running the tessellator: a strip
68    /// is already triangles, and the area series is the hottest path in
69    /// the whole crate.
70    Strip {
71        /// The vertices along the top edge of the strip.
72        points: Vec<Point>,
73        /// The vertical coordinate the strip is closed against.
74        baseline: f32,
75        /// The fill paint.
76        paint: Fill,
77        /// The overall opacity applied to the strip, from `0.0` to `1.0`.
78        opacity: f64,
79    },
80}
81
82/// The kind of a display command, used to group commands that can share
83/// one batch.
84#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
85pub enum DrawKind {
86    /// A filled path.
87    #[default]
88    Fill,
89    /// A stroked path.
90    Stroke,
91    /// A text run.
92    Text,
93    /// An image.
94    Image,
95    /// A clip instruction.
96    Clip,
97    /// A clip-restore instruction.
98    PopClip,
99    /// A filled triangle strip.
100    Strip,
101}