diff options
Diffstat (limited to 'examples/lib-dfscq-log/src/bracket.rs')
-rw-r--r-- | examples/lib-dfscq-log/src/bracket.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/lib-dfscq-log/src/bracket.rs b/examples/lib-dfscq-log/src/bracket.rs new file mode 100644 index 0000000..02bca8d --- /dev/null +++ b/examples/lib-dfscq-log/src/bracket.rs | |||
@@ -0,0 +1,42 @@ | |||
1 | use diaphragm_core::{ | ||
2 | core_shapes::StraightPath, types::ShapeContext, ComplexShape, DrawResult, Drawable, | ||
3 | SolverContext, | ||
4 | }; | ||
5 | |||
6 | #[derive(Copy, Clone)] | ||
7 | pub enum BracketType { | ||
8 | Opening, | ||
9 | Closing, | ||
10 | } | ||
11 | |||
12 | #[derive(Clone)] | ||
13 | pub struct Bracket { | ||
14 | pub r#type: BracketType, | ||
15 | } | ||
16 | |||
17 | impl ComplexShape for Bracket { | ||
18 | fn draw(&self, context: &ShapeContext, solver: &mut dyn SolverContext) -> DrawResult { | ||
19 | let mut result = DrawResult::new(); | ||
20 | |||
21 | let bounds = context.bounds(); | ||
22 | |||
23 | let path = match self.r#type { | ||
24 | BracketType::Opening => StraightPath::new(vec![ | ||
25 | bounds.top_right(solver), | ||
26 | bounds.top_left(solver), | ||
27 | bounds.bottom_left(solver), | ||
28 | bounds.bottom_right(solver), | ||
29 | ]), | ||
30 | BracketType::Closing => StraightPath::new(vec![ | ||
31 | bounds.top_left(solver), | ||
32 | bounds.top_right(solver), | ||
33 | bounds.bottom_right(solver), | ||
34 | bounds.bottom_left(solver), | ||
35 | ]), | ||
36 | }; | ||
37 | |||
38 | result.push(Drawable::new(path, context.clone())); | ||
39 | |||
40 | result | ||
41 | } | ||
42 | } | ||