|
| 1 | +use kurbo::{ |
| 2 | + paths::svg::{self, OneVec}, |
| 3 | + Affine, Line, Point, Size, |
| 4 | +}; |
| 5 | +use snog::{ |
| 6 | + peniko::{Color, Stroke}, |
| 7 | + App, RenderCtx, |
| 8 | +}; |
| 9 | + |
| 10 | +fn main() { |
| 11 | + let data = Data::new(); |
| 12 | + App::new_with_data(data).with_render(render).run() |
| 13 | +} |
| 14 | + |
| 15 | +// TODO both the lifetime of the RenderCtx and the ref to user data could be the same - nothing is |
| 16 | +// gained by having one longer than the other. |
| 17 | +fn render(data: &mut Data, mut ctx: RenderCtx<'_>) { |
| 18 | + let Size { width, height } = ctx.screen().size(); |
| 19 | + |
| 20 | + let stroke = Stroke::new(0.005); |
| 21 | + let scale = Affine::scale_non_uniform(width, height); |
| 22 | + let brush = Color::WHITE; |
| 23 | + ctx.stroke(&stroke, scale, &brush, None, &data.path); |
| 24 | +} |
| 25 | + |
| 26 | +struct Data { |
| 27 | + path: svg::Path, |
| 28 | +} |
| 29 | + |
| 30 | +impl Data { |
| 31 | + fn new() -> Self { |
| 32 | + let path = svg::Path::try_from(vec![ |
| 33 | + svg::PathEl::MoveTo(OneVec::single(Point::new(0.1, 0.1))), |
| 34 | + svg::PathEl::Bearing(std::f64::consts::FRAC_PI_2), |
| 35 | + svg::PathEl::LineToRel( |
| 36 | + OneVec::try_from(vec![Point::new(0.2, 0.0), Point::new(-0.1, -0.2)]).unwrap(), |
| 37 | + ), |
| 38 | + svg::PathEl::VertRel(OneVec::single(-0.2)), |
| 39 | + svg::PathEl::CubicToRel(OneVec::single(svg::CubicTo { |
| 40 | + to: Point::new(0.2, 0.0), |
| 41 | + ctrl1: Point::new(0.1, 0.1), |
| 42 | + ctrl2: Point::new(0.1, -0.1), |
| 43 | + })), |
| 44 | + svg::PathEl::SmoothCubicToRel( |
| 45 | + OneVec::try_from(vec![ |
| 46 | + svg::SmoothCubicTo { |
| 47 | + to: Point::new(0.2, 0.0), |
| 48 | + ctrl2: Point::new(0.1, -0.1), |
| 49 | + }, |
| 50 | + svg::SmoothCubicTo { |
| 51 | + to: Point::new(0.2, 0.0), |
| 52 | + ctrl2: Point::new(0.1, -0.1), |
| 53 | + }, |
| 54 | + ]) |
| 55 | + .unwrap(), |
| 56 | + ), |
| 57 | + svg::PathEl::QuadToRel(OneVec::single(svg::QuadTo { |
| 58 | + to: Point::new(0.0, 0.1), |
| 59 | + ctrl: Point::new(0.1, 0.1), |
| 60 | + })), |
| 61 | + svg::PathEl::SmoothQuadToRel( |
| 62 | + OneVec::try_from(vec![Point::new(0.0, 0.1), Point::new(0.0, 0.1)]).unwrap(), |
| 63 | + ), |
| 64 | + ]) |
| 65 | + .unwrap(); |
| 66 | + |
| 67 | + Data { path } |
| 68 | + } |
| 69 | +} |
0 commit comments