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