pub struct DrawOptions {
fill_color: Option<(u8, u8, u8)>,
stroke_color: Option<(u8, u8, u8)>,
stroke_size: f64,
}
impl DrawOptions {
pub fn default() -> DrawOptions {
DrawOptions {
fill_color: None,
stroke_color: Some((0, 0, 0)),
stroke_size: 2.0,
}
}
pub fn stroked((r, g, b): (u8, u8, u8), size: f64) -> DrawOptions {
DrawOptions {
fill_color: None,
stroke_color: Some((r, g, b)),
stroke_size: size,
}
}
pub fn filled((r, g, b): (u8, u8, u8)) -> DrawOptions {
DrawOptions {
fill_color: Some((r, g, b)),
stroke_color: None,
stroke_size: 0.0,
}
}
}
pub enum Command {
StartShape(DrawOptions),
MoveTo {
x: f64,
y: f64
},
LineTo {
x: f64,
y: f64
},
CubicCurveTo {
cx1: f64,
cy1: f64,
cx2: f64,
cy2: f64,
x: f64,
y: f64,
},
QuadraticCurveTo {
cx: f64,
cy: f64,
x: f64,
y: f64,
},
ArcTo {
rx: f64,
ry: f64,
rotation: f64,
large_arc: bool,
sweep: bool,
x: f64,
y: f64,
},
CloseShape,
EndShape,
}
pub trait DrawBackend {
type Error;
fn apply(&mut self, command: Command) -> Result<(), Self::Error>;
fn close(self) -> Result<(), Self::Error>;
}