summaryrefslogtreecommitdiffstats
path: root/core/src/solving.rs
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/solving.rs
parent30f7d39ca2ed4590b5d356b1a4c024d11156a383 (diff)
downloaddiaphragm-9c15b76c5a6355902b2a105a7c6ee93f6b5016dc.tar.gz
diaphragm-9c15b76c5a6355902b2a105a7c6ee93f6b5016dc.zip
WIP v2: text works, primitives works in Lua
Diffstat (limited to 'core/src/solving.rs')
-rw-r--r--core/src/solving.rs55
1 files changed, 39 insertions, 16 deletions
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// }