1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
mod tuple;
mod circle;
pub use circle::*;
mod paint;
pub use paint::*;
mod aspect;
pub use aspect::*;
mod canvas;
pub use canvas::*;
mod viewbox;
pub use viewbox::*;
mod entity;
pub use entity::*;
mod label;
pub use label::*;
#[cfg(test)]
mod tests {
use crate::{
Angle, Length, MockInstruction, MockRenderer, Point, PreserveAspectRatio, Renderer, Rgba,
Unit,
};
use super::*;
#[test]
fn test_combinator() {
let mut renderer = MockRenderer::default();
canvas(
10.0,
10.0,
viewbox(
10.0,
10.0,
aspect(
Default::default(),
fill(
(255, 0, 255),
stroke(
(255, 0, 255),
1.0,
label(
"content",
(
circle((20.0, 20.0), 10.0),
circle((20.0, 20.0), Length::pc(10.0)),
|renderer: &mut MockRenderer| {
renderer.line((0.0, 0.0).into(), (5.0, 5.0).into());
Ok(())
},
),
),
),
),
),
),
)(&mut renderer)
.unwrap();
assert_eq!(
renderer.instructions(),
&[
MockInstruction::Canvas {
width: Length(10.0, Unit::Px),
height: Length(10.0, Unit::Px)
},
MockInstruction::ViewBox {
width: Length(10.0, Unit::Px),
height: Length(10.0, Unit::Px)
},
MockInstruction::Aspect(PreserveAspectRatio::xMidYMid),
MockInstruction::Fill(Rgba(1.0, 0.0, 1.0, 1.0)),
MockInstruction::Stroke {
color: Rgba(1.0, 0.0, 1.0, 1.0),
width: Length(1.0, Unit::Px)
},
MockInstruction::Label("content".to_owned()),
MockInstruction::Arc {
center: Point {
x: 20.0,
y: 20.0,
unit: Unit::Px
},
raddii: (Length(10.0, Unit::Px), Length(10.0, Unit::Px)),
start_angle: Angle::deg(0.0),
sweep_angle: Angle::deg(360.0),
x_rotation: Angle::deg(0.0)
},
MockInstruction::Arc {
center: Point {
x: 20.0,
y: 20.0,
unit: Unit::Px
},
raddii: (Length(10.0, Unit::Pc), Length(10.0, Unit::Pc)),
start_angle: Angle::deg(0.0),
sweep_angle: Angle::deg(360.0),
x_rotation: Angle::deg(0.0)
},
MockInstruction::Line {
from: Point {
x: 0.0,
y: 0.0,
unit: Unit::Px
},
to: Point {
x: 5.0,
y: 5.0,
unit: Unit::Px
}
},
MockInstruction::Pop(1),
MockInstruction::Pop(1),
MockInstruction::Pop(1),
MockInstruction::Pop(1),
MockInstruction::Pop(1),
MockInstruction::Pop(1)
]
);
}
}