Skip to content

enum

DrawCommand

pub enum DrawCommand {
    Clear { w: f32, h: f32 },
    Save,
    Restore,
    SetFill(String),
    SetFillLinear { x0: f32, y0: f32, x1: f32, y1: f32, from: String, to: String },
    SetFillRadial { x: f32, y: f32, r: f32, from: String, to: String },
    SetStroke(String),
    SetLineWidth(f32),
    SetLineCap(String),
    SetLineJoin(String),
    SetShadow { blur: f32, color: String },
    SetGlobalAlpha(f32),
    SetFont(String),
    SetTextAlign(String),
    FillRect { x: f32, y: f32, w: f32, h: f32 },
    StrokeRect { x: f32, y: f32, w: f32, h: f32 },
    BeginPath,
    MoveTo(f32, f32),
    LineTo(f32, f32),
    QuadTo(f32, f32, f32, f32),
    BezierTo { c1x: f32, c1y: f32, c2x: f32, c2y: f32, x: f32, y: f32 },
    Arc { cx: f32, cy: f32, r: f32, start: f32, end: f32, ccw: bool },
    ClosePath,
    Fill,
    Stroke,
    FillText { text: String, x: f32, y: f32 },
    Image { src: String, tint: Option<String>, x: f32, y: f32, w: f32, h: f32 },
}

One Canvas 2D API call.

Variants

Clear

Clear { w: f32, h: f32 }

clearRect over the whole canvas.

Save

Save

save()

Restore

Restore

restore()

SetFill

SetFill(String)

fillStyle as a colour.

SetFillLinear

SetFillLinear { x0: f32, y0: f32, x1: f32, y1: f32, from: String, to: String }

fillStyle as a linear gradient.

SetFillRadial

SetFillRadial { x: f32, y: f32, r: f32, from: String, to: String }

fillStyle as a radial gradient.

SetStroke

SetStroke(String)

strokeStyle

SetLineWidth

SetLineWidth(f32)

lineWidth

SetLineCap

SetLineCap(String)

lineCap

SetLineJoin

SetLineJoin(String)

lineJoin

SetShadow

SetShadow { blur: f32, color: String }

shadowBlur and shadowColor.

SetGlobalAlpha

SetGlobalAlpha(f32)

globalAlpha

SetFont

SetFont(String)

font

SetTextAlign

SetTextAlign(String)

textAlign

FillRect

FillRect { x: f32, y: f32, w: f32, h: f32 }

fillRect

StrokeRect

StrokeRect { x: f32, y: f32, w: f32, h: f32 }

strokeRect

BeginPath

BeginPath

beginPath()

MoveTo

MoveTo(f32, f32)

moveTo(x, y)

LineTo

LineTo(f32, f32)

lineTo(x, y)

QuadTo

QuadTo(f32, f32, f32, f32)

Quadratic curve: control point, end point.

BezierTo

BezierTo { c1x: f32, c1y: f32, c2x: f32, c2y: f32, x: f32, y: f32 }

bezierCurveTo

Arc

Arc { cx: f32, cy: f32, r: f32, start: f32, end: f32, ccw: bool }

Angles in radians, canvas convention (0 = 3 o'clock).

ClosePath

ClosePath

closePath()

Fill

Fill

fill()

Stroke

Stroke

stroke()

FillText

FillText { text: String, x: f32, y: f32 }

fillText

Image

Image { src: String, tint: Option<String>, x: f32, y: f32, w: f32, h: f32 }

An image by URL, drawn once loaded. An SVG with a tint has its colours replaced by it.

Trait implementations