summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2022-12-29 01:40:08 +0100
committerMinijackson <minijackson@riseup.net>2022-12-29 01:40:08 +0100
commit9c15b76c5a6355902b2a105a7c6ee93f6b5016dc (patch)
tree44cacfe756169f7b3d3cc23f875864683ba2af74 /core/src
parent30f7d39ca2ed4590b5d356b1a4c024d11156a383 (diff)
downloaddiaphragm-9c15b76c5a6355902b2a105a7c6ee93f6b5016dc.tar.gz
diaphragm-9c15b76c5a6355902b2a105a7c6ee93f6b5016dc.zip
WIP v2: text works, primitives works in Lua
Diffstat (limited to 'core/src')
-rw-r--r--core/src/core_shapes.rs73
-rw-r--r--core/src/lib.rs8
-rw-r--r--core/src/rendering.rs53
-rw-r--r--core/src/runtime.rs154
-rw-r--r--core/src/solving.rs55
-rw-r--r--core/src/types.rs110
6 files changed, 277 insertions, 176 deletions
diff --git a/core/src/core_shapes.rs b/core/src/core_shapes.rs
index 805d82e..d8017ab 100644
--- a/core/src/core_shapes.rs
+++ b/core/src/core_shapes.rs
@@ -1,8 +1,44 @@
1use super::complex_shapes::{ComplexShape, DrawResult}; 1pub struct CoreDrawable {
2use super::rendering::{Render, Renderer}; 2 pub(crate) shape: CoreShape,
3use super::solving::{Constrainable, SolverContext, SolverModel}; 3 pub(crate) context: CoreShapeContext,
4use super::types::*; 4}
5
6impl CoreDrawable {
7 pub fn new(shape: CoreShape, context: CoreShapeContext) -> Self {
8 Self { shape, context }
9 }
10}
11
12pub enum CoreShape {
13 Rectangle(Rectangle),
14 Text(Text),
15 // StraightPath(StraightPath),
16}
5 17
18impl From<Rectangle> for CoreShape {
19 fn from(rectangle: Rectangle) -> Self {
20 CoreShape::Rectangle(rectangle)
21 }
22}
23
24impl From<Text> for CoreShape {
25 fn from(text: Text) -> Self {
26 CoreShape::Text(text)
27 }
28}
29
30pub struct DefinedCoreDrawable {
31 pub(crate) shape: DefinedCoreShape,
32 pub(crate) context: DefinedCoreShapeContext,
33}
34
35pub enum DefinedCoreShape {
36 Rectangle(Rectangle),
37 Text(DefinedText),
38 // StraightPath(StraightPath),
39}
40
41/*
6pub trait CoreShape { 42pub trait CoreShape {
7 fn constrain( 43 fn constrain(
8 &self, 44 &self,
@@ -23,19 +59,25 @@ impl<T: CoreShape + Clone + 'static> ComplexShape for T {
23 panic!("Tried to decompose core shape") 59 panic!("Tried to decompose core shape")
24 } 60 }
25} 61}
62*/
26 63
27// TODO: add default 64// TODO: add default
28#[derive(Copy, Clone, Debug, Default)] 65#[derive(Copy, Clone, Debug, Default)]
29pub struct Rectangle {} 66pub struct Rectangle {}
30 67
68/*
31impl CoreShape for Rectangle { 69impl CoreShape for Rectangle {
32 fn to_render(&self, _model: &dyn SolverModel) -> Option<Box<dyn Render>> { 70 fn to_render(&self, _model: &dyn SolverModel) -> Option<Box<dyn Render>> {
33 Some(Box::new(*self)) 71 Some(Box::new(*self))
34 } 72 }
35} 73}
74*/
75
76use crate::types::{CoreShapeContext, DefinedCoreShapeContext};
36 77
37pub use super::text::{DefinedText, Text}; 78pub use super::text::{DefinedText, Text};
38 79
80/*
39impl CoreShape for Text { 81impl CoreShape for Text {
40 fn constrain( 82 fn constrain(
41 &self, 83 &self,
@@ -62,18 +104,20 @@ impl CoreShape for Text {
62 .map(|path| -> Box<dyn Render> { Box::new(path) }) 104 .map(|path| -> Box<dyn Render> { Box::new(path) })
63 } 105 }
64} 106}
107*/
65 108
66#[derive(Clone, Debug, Default)] 109// #[derive(Clone, Debug, Default)]
67pub struct StraightPath { 110// pub struct StraightPath {
68 pub(crate) points: Vec<Point2D>, 111// pub(crate) points: Vec<Point2D>,
69} 112// }
70 113//
71impl StraightPath { 114// impl StraightPath {
72 pub fn new(points: Vec<Point2D>) -> Self { 115// pub fn new(points: Vec<Point2D>) -> Self {
73 Self { points } 116// Self { points }
74 } 117// }
75} 118// }
76 119
120/*
77pub struct DefinedStraightPath { 121pub struct DefinedStraightPath {
78 pub(crate) points: Vec<DefinedPoint2D>, 122 pub(crate) points: Vec<DefinedPoint2D>,
79} 123}
@@ -84,3 +128,4 @@ impl CoreShape for StraightPath {
84 .map(|path| -> Box<dyn Render> { Box::new(path) }) 128 .map(|path| -> Box<dyn Render> { Box::new(path) })
85 } 129 }
86} 130}
131*/
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 57e45df..f949cd9 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -2,7 +2,7 @@
2#![deny(unsafe_code)] 2#![deny(unsafe_code)]
3 3
4pub mod colors; 4pub mod colors;
5mod complex_shapes; 5// mod complex_shapes;
6pub mod core_shapes; 6pub mod core_shapes;
7mod rendering; 7mod rendering;
8mod runtime; 8mod runtime;
@@ -11,9 +11,9 @@ pub mod styles;
11pub mod text; 11pub mod text;
12pub mod types; 12pub mod types;
13 13
14pub use complex_shapes::{ 14// pub use complex_shapes::{
15 ComplexShape, DrawResult, Drawable, DrawableBuilder, DynClone, DynDrawable, 15// ComplexShape, DrawResult, Drawable, DrawableBuilder, DynClone, DynDrawable,
16}; 16// };
17pub use rendering::Renderer; 17pub use rendering::Renderer;
18pub use runtime::Runtime; 18pub use runtime::Runtime;
19pub use solving::{SolverContext, SolverModel}; 19pub use solving::{SolverContext, SolverModel};
diff --git a/core/src/rendering.rs b/core/src/rendering.rs
index f7a0189..9c9f9e4 100644
--- a/core/src/rendering.rs
+++ b/core/src/rendering.rs
@@ -1,7 +1,7 @@
1use super::core_shapes::*; 1use super::core_shapes::*;
2use super::styles::{DefinedDashStyle, DefinedStrokeStyle, FillStyle, Pattern}; 2use super::styles::{DefinedDashStyle, DefinedStrokeStyle, FillStyle, Pattern};
3use super::text::{DefinedFontDescription, FontDescription}; 3use super::text::{DefinedFontDescription, FontDescription};
4use super::types::DefinedShapeContext; 4use super::types::DefinedCoreShapeContext;
5 5
6pub trait Renderer { 6pub trait Renderer {
7 fn move_to(&mut self, x: f64, y: f64); 7 fn move_to(&mut self, x: f64, y: f64);
@@ -20,7 +20,16 @@ pub trait Renderer {
20} 20}
21 21
22pub trait Render { 22pub trait Render {
23 fn render(&self, context: DefinedShapeContext, renderer: &mut dyn Renderer); 23 fn render(&self, context: DefinedCoreShapeContext, renderer: &mut dyn Renderer);
24}
25
26impl Render for DefinedCoreShape {
27 fn render(&self, context: DefinedCoreShapeContext, renderer: &mut dyn Renderer) {
28 match self {
29 Self::Rectangle(r) => r.render(context, renderer),
30 Self::Text(t) => t.render(context, renderer),
31 }
32 }
24} 33}
25 34
26fn draw(fill: &FillStyle, stroke: &DefinedStrokeStyle, renderer: &mut dyn Renderer) { 35fn draw(fill: &FillStyle, stroke: &DefinedStrokeStyle, renderer: &mut dyn Renderer) {
@@ -47,7 +56,7 @@ fn draw(fill: &FillStyle, stroke: &DefinedStrokeStyle, renderer: &mut dyn Render
47} 56}
48 57
49impl Render for Rectangle { 58impl Render for Rectangle {
50 fn render(&self, context: DefinedShapeContext, renderer: &mut dyn Renderer) { 59 fn render(&self, context: DefinedCoreShapeContext, renderer: &mut dyn Renderer) {
51 let bounds = &context.bounds; 60 let bounds = &context.bounds;
52 renderer.rectangle(bounds.left, bounds.top, bounds.width, bounds.height); 61 renderer.rectangle(bounds.left, bounds.top, bounds.width, bounds.height);
53 draw(&context.fill, &context.stroke, renderer); 62 draw(&context.fill, &context.stroke, renderer);
@@ -55,7 +64,7 @@ impl Render for Rectangle {
55} 64}
56 65
57impl Render for DefinedText { 66impl Render for DefinedText {
58 fn render(&self, context: DefinedShapeContext, renderer: &mut dyn Renderer) { 67 fn render(&self, context: DefinedCoreShapeContext, renderer: &mut dyn Renderer) {
59 // TODO: select font, style, text shaping (renderer specific), etc. 68 // TODO: select font, style, text shaping (renderer specific), etc.
60 let bounds = &context.bounds; 69 let bounds = &context.bounds;
61 //renderer.move_to(bounds.left, bounds.top + self.font.size); 70 //renderer.move_to(bounds.left, bounds.top + self.font.size);
@@ -66,21 +75,21 @@ impl Render for DefinedText {
66 } 75 }
67} 76}
68 77
69impl Render for DefinedStraightPath { 78// impl Render for DefinedStraightPath {
70 fn render(&self, context: DefinedShapeContext, renderer: &mut dyn Renderer) { 79// fn render(&self, context: DefinedShapeContext, renderer: &mut dyn Renderer) {
71 let mut iter = self.points.iter(); 80// let mut iter = self.points.iter();
72 81//
73 let first_point = match iter.next() { 82// let first_point = match iter.next() {
74 Some(point) => point, 83// Some(point) => point,
75 None => return, 84// None => return,
76 }; 85// };
77 86//
78 renderer.move_to(first_point.x, first_point.y); 87// renderer.move_to(first_point.x, first_point.y);
79 88//
80 for point in iter { 89// for point in iter {
81 renderer.line_to(point.x, point.y); 90// renderer.line_to(point.x, point.y);
82 } 91// }
83 92//
84 draw(&context.fill, &context.stroke, renderer); 93// draw(&context.fill, &context.stroke, renderer);
85 } 94// }
86} 95// }
diff --git a/core/src/runtime.rs b/core/src/runtime.rs
index bfb31fa..d70e4d0 100644
--- a/core/src/runtime.rs
+++ b/core/src/runtime.rs
@@ -1,13 +1,17 @@
1use super::complex_shapes::{ComplexShape, Drawable, DynDrawable}; 1use crate::core_shapes::CoreDrawable;
2use crate::rendering::Render;
3
4// use super::complex_shapes::{ComplexShape, Drawable};
2use super::rendering::Renderer; 5use super::rendering::Renderer;
3use super::solving::{Constrainable, SolverContext}; 6use super::solving::{Constrainable, SolverContext};
4 7
5const RECURSION_LIMIT: u64 = 10_000; 8// const RECURSION_LIMIT: u64 = 10_000;
6 9
7pub struct Runtime<'a> { 10pub struct Runtime<'a> {
8 solver_ctx: Box<dyn SolverContext + 'a>, 11 solver_ctx: Box<dyn SolverContext + 'a>,
9 renderer: Box<dyn Renderer>, 12 renderer: Box<dyn Renderer>,
10 drawables: Vec<DynDrawable>, 13 // drawables: Vec<DynDrawable>,
14 drawables: Vec<CoreDrawable>,
11} 15}
12 16
13impl<'a> Runtime<'a> { 17impl<'a> Runtime<'a> {
@@ -15,81 +19,101 @@ impl<'a> Runtime<'a> {
15 Self { 19 Self {
16 solver_ctx, 20 solver_ctx,
17 renderer, 21 renderer,
22 // drawables: Vec::new(),
18 drawables: Vec::new(), 23 drawables: Vec::new(),
19 } 24 }
20 } 25 }
21 26
22 pub fn add_drawable<T: ComplexShape + 'static>(&mut self, drawable: Drawable<T>) { 27 // pub fn add_drawable<T: ComplexShape + 'static>(&mut self, drawable: Drawable<T>) {
23 self.drawables.push(drawable.into()) 28 // self.drawables.push(drawable.into())
29 // }
30
31 pub fn add_drawable(&mut self, drawable: CoreDrawable) {
32 self.drawables.push(drawable)
24 } 33 }
25 34
26 pub fn solver_ctx(&mut self) -> &mut (dyn SolverContext + 'a) { 35 pub fn solver_ctx(&mut self) -> &mut (dyn SolverContext + 'a) {
27 &mut *self.solver_ctx 36 &mut *self.solver_ctx
28 } 37 }
29 38
30 // TODO: preserve ordering of shapes 39 pub fn renderer(&mut self) -> &mut dyn Renderer {
31 pub fn render(mut self) { 40 &mut *self.renderer
32 let mut drawables = self.drawables; 41 }
33 let mut waited_on_variables = Vec::new();
34 let mut core_shapes = Vec::new();
35
36 /*
37 for drawable in &self.shapes {
38 let bounds = &drawable.bounds;
39 let shape = &drawable.shape;
40
41 if let Some(core_shape) = shape.to_render() {
42 drawables.push((*drawable).clone());
43 continue;
44 }
45
46 let mut result = shape.draw(bounds);
47 drawables.append(&mut result.subshapes);
48 waited_on_variables.append(&mut result.waiting_on);
49 }
50 */
51
52 let mut recursion_count = 0;
53
54 while !drawables.is_empty() {
55 recursion_count += 1;
56
57 if recursion_count > RECURSION_LIMIT {
58 panic!("Recursion limit reached");
59 }
60
61 let mut tmp_drawables = Vec::new();
62
63 for drawable in drawables.drain(..) {
64 let shape_ctx = &drawable.context;
65 let shape = &drawable.shape;
66
67 if let Some(core_shape) = shape.as_core_shape() {
68 core_shape.constrain(shape_ctx, &mut *self.solver_ctx, &*self.renderer);
69 core_shapes.push((shape.dyn_clone(), shape_ctx.clone())); // Better to Arc? Cow?
70 continue;
71 }
72
73 let mut result = shape.draw(shape_ctx, &mut *self.solver_ctx);
74 tmp_drawables.append(&mut result.subshapes);
75 waited_on_variables.append(&mut result.waiting_on);
76 }
77
78 drawables = tmp_drawables;
79 }
80 42
43 pub fn render(mut self) {
81 let model = self.solver_ctx.solve(); 44 let model = self.solver_ctx.solve();
82 45
83 // Delay rendering core shapes until later to have all the constraints 46 for drawable in &self.drawables {
84 for (core_shape, shape_ctx) in core_shapes { 47 let defined_drawable = drawable
85 let core_shape = core_shape.as_core_shape().unwrap(); 48 .fixate(&*model)
86 49 .expect("Could not fixate core shape");
87 match (core_shape.to_render(&*model), shape_ctx.fixate(&*model)) { 50 defined_drawable.shape.render(defined_drawable.context, &mut *self.renderer);
88 (Some(defined_shape), Some(shape_ctx)) => {
89 defined_shape.render(shape_ctx, &mut *self.renderer)
90 }
91 _ => panic!("Failed to fixate core shape"),
92 }
93 } 51 }
94 } 52 }
53
54 // TODO: preserve ordering of shapes
55 // pub fn render(mut self) {
56 // let mut drawables = self.drawables;
57 // let mut waited_on_variables = Vec::new();
58 // let mut core_shapes = Vec::new();
59 //
60 // /*
61 // for drawable in &self.shapes {
62 // let bounds = &drawable.bounds;
63 // let shape = &drawable.shape;
64 //
65 // if let Some(core_shape) = shape.to_render() {
66 // drawables.push((*drawable).clone());
67 // continue;
68 // }
69 //
70 // let mut result = shape.draw(bounds);
71 // drawables.append(&mut result.subshapes);
72 // waited_on_variables.append(&mut result.waiting_on);
73 // }
74 // */
75 //
76 // let mut recursion_count = 0;
77 //
78 // while !drawables.is_empty() {
79 // recursion_count += 1;
80 //
81 // if recursion_count > RECURSION_LIMIT {
82 // panic!("Recursion limit reached");
83 // }
84 //
85 // let mut tmp_drawables = Vec::new();
86 //
87 // for drawable in drawables.drain(..) {
88 // let shape_ctx = &drawable.context;
89 // let shape = &drawable.shape;
90 //
91 // if let Some(core_shape) = shape.as_core_shape() {
92 // core_shape.constrain(shape_ctx, &mut *self.solver_ctx, &*self.renderer);
93 // core_shapes.push((shape.dyn_clone(), shape_ctx.clone())); // Better to Arc? Cow?
94 // continue;
95 // }
96 //
97 // let mut result = shape.draw(shape_ctx, &mut *self.solver_ctx);
98 // tmp_drawables.append(&mut result.subshapes);
99 // waited_on_variables.append(&mut result.waiting_on);
100 // }
101 //
102 // drawables = tmp_drawables;
103 // }
104 //
105 // let model = self.solver_ctx.solve();
106 //
107 // // Delay rendering core shapes until later to have all the constraints
108 // for (core_shape, shape_ctx) in core_shapes {
109 // let core_shape = core_shape.as_core_shape().unwrap();
110 //
111 // match (core_shape.to_render(&*model), shape_ctx.fixate(&*model)) {
112 // (Some(defined_shape), Some(shape_ctx)) => {
113 // defined_shape.render(shape_ctx, &mut *self.renderer)
114 // }
115 // _ => panic!("Failed to fixate core shape"),
116 // }
117 // }
118 // }
95} 119}
diff --git a/core/src/solving.rs b/core/src/solving.rs
index 4760611..261b4d4 100644
--- a/core/src/solving.rs
+++ b/core/src/solving.rs
@@ -1,4 +1,5 @@
1use super::core_shapes::*; 1use crate::core_shapes::{CoreDrawable, CoreShape, DefinedCoreDrawable, DefinedCoreShape};
2
2use super::styles::*; 3use super::styles::*;
3use super::text::*; 4use super::text::*;
4use super::types::{Bool, Float}; 5use super::types::{Bool, Float};
@@ -147,6 +148,17 @@ pub trait Constrainable {
147 fn fixate(&self, model: &dyn SolverModel) -> Option<Self::Fixated>; 148 fn fixate(&self, model: &dyn SolverModel) -> Option<Self::Fixated>;
148} 149}
149 150
151impl Constrainable for CoreShape {
152 type Fixated = DefinedCoreShape;
153
154 fn fixate(&self, model: &dyn SolverModel) -> Option<Self::Fixated> {
155 match self {
156 CoreShape::Rectangle(r) => Some(DefinedCoreShape::Rectangle(*r)),
157 CoreShape::Text(t) => t.fixate(model).map(DefinedCoreShape::Text),
158 }
159 }
160}
161
150impl Constrainable for Float { 162impl Constrainable for Float {
151 type Fixated = f64; 163 type Fixated = f64;
152 164
@@ -218,11 +230,22 @@ impl Constrainable for DashStyle {
218 } 230 }
219} 231}
220 232
221impl Constrainable for ShapeContext { 233impl Constrainable for CoreDrawable {
222 type Fixated = DefinedShapeContext; 234 type Fixated = DefinedCoreDrawable;
235
236 fn fixate(&self, model: &dyn SolverModel) -> Option<Self::Fixated> {
237 Some(DefinedCoreDrawable {
238 shape: self.shape.fixate(model)?,
239 context: self.context.fixate(model)?,
240 })
241 }
242}
243
244impl Constrainable for CoreShapeContext {
245 type Fixated = DefinedCoreShapeContext;
223 246
224 fn fixate(&self, model: &dyn SolverModel) -> Option<Self::Fixated> { 247 fn fixate(&self, model: &dyn SolverModel) -> Option<Self::Fixated> {
225 Some(DefinedShapeContext { 248 Some(DefinedCoreShapeContext {
226 bounds: self.bounds.fixate(model)?, 249 bounds: self.bounds.fixate(model)?,
227 fill: self.fill.clone(), 250 fill: self.fill.clone(),
228 stroke: self.stroke.fixate(model)?, 251 stroke: self.stroke.fixate(model)?,
@@ -265,15 +288,15 @@ impl Constrainable for Text {
265 } 288 }
266} 289}
267 290
268impl Constrainable for StraightPath { 291// impl Constrainable for StraightPath {
269 type Fixated = DefinedStraightPath; 292// type Fixated = DefinedStraightPath;
270 293//
271 fn fixate(&self, model: &dyn SolverModel) -> Option<Self::Fixated> { 294// fn fixate(&self, model: &dyn SolverModel) -> Option<Self::Fixated> {
272 let points: Option<_> = self 295// let points: Option<_> = self
273 .points 296// .points
274 .iter() 297// .iter()
275 .map(|point| point.fixate(model)) 298// .map(|point| point.fixate(model))
276 .collect(); 299// .collect();
277 Some(DefinedStraightPath { points: points? }) 300// Some(DefinedStraightPath { points: points? })
278 } 301// }
279} 302// }
diff --git a/core/src/types.rs b/core/src/types.rs
index 1b7623a..96e059a 100644
--- a/core/src/types.rs
+++ b/core/src/types.rs
@@ -99,19 +99,19 @@ impl Bounds {
99 BoundsBuilder::default() 99 BoundsBuilder::default()
100 } 100 }
101 101
102 pub fn top(&self, _ctx: &mut dyn SolverContext) -> Float { 102 pub fn top(&self, _solver: &mut dyn SolverContext) -> Float {
103 self.top 103 self.top
104 } 104 }
105 105
106 pub fn left(&self, _ctx: &mut dyn SolverContext) -> Float { 106 pub fn left(&self, _solver: &mut dyn SolverContext) -> Float {
107 self.left 107 self.left
108 } 108 }
109 109
110 pub fn width(&self, _ctx: &mut dyn SolverContext) -> Float { 110 pub fn width(&self, _solver: &mut dyn SolverContext) -> Float {
111 self.width 111 self.width
112 } 112 }
113 113
114 pub fn height(&self, _ctx: &mut dyn SolverContext) -> Float { 114 pub fn height(&self, _solver: &mut dyn SolverContext) -> Float {
115 self.height 115 self.height
116 } 116 }
117 117
@@ -133,7 +133,7 @@ impl Bounds {
133 solver.float_add(&[self.left, half_width]) 133 solver.float_add(&[self.left, half_width])
134 } 134 }
135 135
136 pub fn top_left(&self, _ctx: &mut dyn SolverContext) -> Point2D { 136 pub fn top_left(&self, _solver: &mut dyn SolverContext) -> Point2D {
137 Point2D::new(self.left, self.top) 137 Point2D::new(self.left, self.top)
138 } 138 }
139 139
@@ -206,11 +206,11 @@ impl BoundsBuilder {
206 } 206 }
207} 207}
208 208
209#[derive(Clone, Debug)] 209// #[derive(Clone, Debug)]
210pub struct Bounded<Shape> { 210// pub struct Bounded<Shape> {
211 pub bounds: Bounds, 211// pub bounds: Bounds,
212 pub shape: Shape, 212// pub shape: Shape,
213} 213// }
214 214
215#[derive(Clone, PartialEq, PartialOrd, Debug)] 215#[derive(Clone, PartialEq, PartialOrd, Debug)]
216pub struct DefinedBounds { 216pub struct DefinedBounds {
@@ -220,20 +220,20 @@ pub struct DefinedBounds {
220 pub height: f64, 220 pub height: f64,
221} 221}
222 222
223#[derive(Clone, PartialEq, PartialOrd, Debug)] 223// #[derive(Clone, PartialEq, PartialOrd, Debug)]
224pub struct DefinitelyBounded<Shape> { 224// pub struct DefinitelyBounded<Shape> {
225 pub bounds: DefinedBounds, 225// pub bounds: DefinedBounds,
226 pub shape: Shape, 226// pub shape: Shape,
227} 227// }
228 228
229#[derive(Clone, Debug)] 229#[derive(Clone, Debug)]
230pub struct ShapeContext { 230pub struct CoreShapeContext {
231 pub(crate) bounds: Bounds, 231 pub(crate) bounds: Bounds,
232 pub(crate) fill: FillStyle, 232 pub(crate) fill: FillStyle,
233 pub(crate) stroke: StrokeStyle, 233 pub(crate) stroke: StrokeStyle,
234} 234}
235 235
236impl ShapeContext { 236impl CoreShapeContext {
237 pub fn new(solver: &mut dyn SolverContext) -> Self { 237 pub fn new(solver: &mut dyn SolverContext) -> Self {
238 Self { 238 Self {
239 bounds: Bounds { 239 bounds: Bounds {
@@ -247,9 +247,9 @@ impl ShapeContext {
247 } 247 }
248 } 248 }
249 249
250 pub(crate) fn builder() -> ShapeContextBuilder { 250 // pub(crate) fn builder() -> ShapeContextBuilder {
251 ShapeContextBuilder::default() 251 // ShapeContextBuilder::default()
252 } 252 // }
253 253
254 pub fn bounds(&self) -> &Bounds { 254 pub fn bounds(&self) -> &Bounds {
255 &self.bounds 255 &self.bounds
@@ -276,41 +276,41 @@ impl ShapeContext {
276 } 276 }
277} 277}
278 278
279#[derive(Clone, Default)] 279// #[derive(Clone, Default)]
280pub(crate) struct ShapeContextBuilder { 280// pub(crate) struct ShapeContextBuilder {
281 bounds: Option<Bounds>, 281// bounds: Option<Bounds>,
282 fill: Option<FillStyle>, 282// fill: Option<FillStyle>,
283 stroke: Option<StrokeStyle>, 283// stroke: Option<StrokeStyle>,
284} 284// }
285 285//
286impl ShapeContextBuilder { 286// impl ShapeContextBuilder {
287 pub fn bounds(&mut self, bounds: Bounds) -> &mut Self { 287// pub fn bounds(&mut self, bounds: Bounds) -> &mut Self {
288 self.bounds = Some(bounds); 288// self.bounds = Some(bounds);
289 self 289// self
290 } 290// }
291 291//
292 pub fn fill(&mut self, fill: FillStyle) -> &mut Self { 292// pub fn fill(&mut self, fill: FillStyle) -> &mut Self {
293 self.fill = Some(fill); 293// self.fill = Some(fill);
294 self 294// self
295 } 295// }
296 296//
297 pub fn stroke(&mut self, stroke: StrokeStyle) -> &mut Self { 297// pub fn stroke(&mut self, stroke: StrokeStyle) -> &mut Self {
298 self.stroke = Some(stroke); 298// self.stroke = Some(stroke);
299 self 299// self
300 } 300// }
301 301//
302 pub fn build(&self, solver: &mut dyn SolverContext) -> ShapeContext { 302// pub fn build(&self, solver: &mut dyn SolverContext) -> ShapeContext {
303 ShapeContext { 303// ShapeContext {
304 bounds: self.bounds.clone().unwrap_or_else(|| Bounds::builder().build(solver)), 304// bounds: self.bounds.clone().unwrap_or_else(|| Bounds::builder().build(solver)),
305 fill: self.fill.clone().unwrap_or_default(), 305// fill: self.fill.clone().unwrap_or_default(),
306 stroke: self.stroke.clone().unwrap_or_default(), 306// stroke: self.stroke.clone().unwrap_or_default(),
307 } 307// }
308 } 308// }
309} 309// }
310 310
311#[derive(Clone, Debug)] 311#[derive(Clone, Debug)]
312pub struct DefinedShapeContext { 312pub struct DefinedCoreShapeContext {
313 pub bounds: DefinedBounds, 313 pub(crate) bounds: DefinedBounds,
314 pub fill: FillStyle, 314 pub(crate) fill: FillStyle,
315 pub stroke: DefinedStrokeStyle, 315 pub(crate) stroke: DefinedStrokeStyle,
316} 316}