pub enum DrawOp {
Fill(Shape, Paint),
Stroke(Shape, Paint, StrokeStyle),
Text {
text: String,
at: Point,
size: f64,
color: Color,
anchor: TextAnchor,
font: CanvasFont,
},
Stamp(Box<Stamp>),
Image {
image: BitmapId,
rect: Rect,
opacity: f64,
source: Option<Rect>,
},
Clip(Shape),
Shadow(Option<Shadow>),
Blend(BlendMode),
Save,
Restore,
Concat(Affine),
}Variants§
Fill(Shape, Paint)
Stroke(Shape, Paint, StrokeStyle)
Stroke shape. The paint may be a gradient, and StrokeStyle carries width, dash, cap
and join; Draw::stroke builds the plain width-only case.
Text
One line of text. size is absolute canvas points (no accessibility scale: canvas
text is a label inside a drawing, docs/canvas.md); font picks the family, weight and
slant, and its default is the platform’s own UI face.
Stamp(Box<Stamp>)
Draw one shape at many positions, the batched form of DrawOp::Fill/DrawOp::Stroke
(docs/canvas.md “Stamping”).
Boxed because the payload is wider than the largest other op, and a bigger DrawOp would
cost every op in every drawing, the exact thing this variant exists to stop paying.
Image
Draw an image into rect (docs/images.md).
The source is a BitmapId and never bytes: a canvas re-records on every tracked read,
so carrying a buffer here would hand the backend a megabyte to compare, and re-decode, on
every frame. The app decodes once with day::decode_image and draws the handle.
opacity multiplies the image’s own alpha. A backend that cannot draw a bitmap at all
draws nothing rather than a placeholder rectangle, the same way an unknown op is skipped.
source is the region of the bitmap to draw, in the bitmap’s own PIXELS (not points:
BitmapInfo::scale says how many pixels make a point), None meaning the whole
image. It is what lets one decoded sprite sheet serve every icon on a map: each draw
picks its cell and scales it into rect. A region reaching outside the bitmap is clamped
to it, never an error: the part inside draws where the mapping into rect puts it, and
an empty intersection draws nothing. A backend without a sub-rect draw clips to rect
and draws the whole image scaled so the region lands there (clamp_image_source is
the shared arithmetic).
Clip(Shape)
Intersect the clip with shape; everything drawn afterwards is confined to it.
Scoped by DrawOp::Save/DrawOp::Restore, which is the only way to widen a clip
again; every native 2-D context works this way, so there is no “unclip”.
Shadow(Option<Shadow>)
Set the shadow everything drawn afterwards casts, or None to stop casting one
(docs/canvas.md “Shadows”). Graphics state like the clip: DrawOp::Restore puts back
the shadow that was set at the matching DrawOp::Save.
A backend whose 2-D context has no shadow draws the shapes without one; it never draws a hard-edged stand-in.
Blend(BlendMode)
Set how everything drawn afterwards combines with what is already on the canvas
(docs/canvas.md “Blend modes”). Graphics state, scoped by DrawOp::Save and
DrawOp::Restore like the clip and the shadow.
Save
Push the current transform, clip, shadow and blend mode (§11, shapes). Backends map to
save/restore of the native 2-D context; Concat multiplies an affine onto the CTM (shape
rotate/scale/offset).