Skip to content

Commit 071ccbd

Browse files
committed
WIP
1 parent b4b33b7 commit 071ccbd

File tree

4 files changed

+672
-12
lines changed

4 files changed

+672
-12
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ features = ["derive"]
4848
# This is used for research but not really needed; maybe refactor.
4949
[dev-dependencies]
5050
rand = "0.8.0"
51+
snog = { git = "https://github.com/derekdreery/snog" }
5152

5253
[target.'cfg(target_arch="wasm32")'.dev-dependencies]
5354
getrandom = { version = "0.2.0", features = ["js"] }
55+
56+
[patch.crates-io]
57+
kurbo = { path = "." }

examples/svg_path.rs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}

src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ mod rounded_rect_radii;
108108
mod shape;
109109
pub mod simplify;
110110
mod size;
111-
#[cfg(feature = "std")]
112-
mod svg;
111+
//#[cfg(feature = "std")]
112+
//mod svg;
113113
mod translate_scale;
114114
mod vec2;
115115

@@ -131,7 +131,7 @@ pub use crate::rounded_rect::*;
131131
pub use crate::rounded_rect_radii::*;
132132
pub use crate::shape::*;
133133
pub use crate::size::*;
134-
#[cfg(feature = "std")]
135-
pub use crate::svg::*;
134+
//#[cfg(feature = "std")]
135+
//pub use crate::svg::*;
136136
pub use crate::translate_scale::*;
137137
pub use crate::vec2::*;

0 commit comments

Comments
 (0)