diff options
author | Minijackson <minijackson@riseup.net> | 2023-01-04 09:36:12 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2023-01-04 09:36:12 +0100 |
commit | b980a73988e3d61bf7fa8a7a7dd2c4c241535a4f (patch) | |
tree | 9cc4e7312c237519dbae6ccc93655cfdcd89a4d0 /core/src | |
parent | c407a7772e5354bbd13447f7e217e526d662d6cb (diff) | |
download | diaphragm-b980a73988e3d61bf7fa8a7a7dd2c4c241535a4f.tar.gz diaphragm-b980a73988e3d61bf7fa8a7a7dd2c4c241535a4f.zip |
core: make line_width optional, add CoreStyle accessors
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/solving.rs | 7 | ||||
-rw-r--r-- | core/src/styles.rs | 41 |
2 files changed, 41 insertions, 7 deletions
diff --git a/core/src/solving.rs b/core/src/solving.rs index bf5fe95..016d188 100644 --- a/core/src/solving.rs +++ b/core/src/solving.rs | |||
@@ -211,10 +211,15 @@ impl Constrainable for StrokeStyle { | |||
211 | None => None, | 211 | None => None, |
212 | }; | 212 | }; |
213 | 213 | ||
214 | let line_width = match self.line_width { | ||
215 | Some(f) => f.fixate(model)?, | ||
216 | None => 2., | ||
217 | }; | ||
218 | |||
214 | Some(DefinedStrokeStyle { | 219 | Some(DefinedStrokeStyle { |
215 | pattern: self.pattern, | 220 | pattern: self.pattern, |
216 | dash, | 221 | dash, |
217 | line_width: self.line_width.fixate(model)?, | 222 | line_width, |
218 | }) | 223 | }) |
219 | } | 224 | } |
220 | } | 225 | } |
diff --git a/core/src/styles.rs b/core/src/styles.rs index 73373ba..e0bfc80 100644 --- a/core/src/styles.rs +++ b/core/src/styles.rs | |||
@@ -31,6 +31,14 @@ impl FillStyle { | |||
31 | pattern: Pattern::Solid(color), | 31 | pattern: Pattern::Solid(color), |
32 | } | 32 | } |
33 | } | 33 | } |
34 | |||
35 | pub fn pattern(&self) -> Pattern { | ||
36 | self.pattern | ||
37 | } | ||
38 | |||
39 | pub fn set_pattern(&mut self, pattern: Pattern) { | ||
40 | self.pattern = pattern; | ||
41 | } | ||
34 | } | 42 | } |
35 | 43 | ||
36 | impl Default for FillStyle { | 44 | impl Default for FillStyle { |
@@ -46,7 +54,7 @@ impl Default for FillStyle { | |||
46 | pub struct StrokeStyle { | 54 | pub struct StrokeStyle { |
47 | pub(crate) pattern: Pattern, | 55 | pub(crate) pattern: Pattern, |
48 | pub(crate) dash: Option<DashStyle>, | 56 | pub(crate) dash: Option<DashStyle>, |
49 | pub(crate) line_width: Float, | 57 | pub(crate) line_width: Option<Float>, |
50 | } | 58 | } |
51 | 59 | ||
52 | impl StrokeStyle { | 60 | impl StrokeStyle { |
@@ -54,13 +62,37 @@ impl StrokeStyle { | |||
54 | StrokeStyle { | 62 | StrokeStyle { |
55 | pattern: Pattern::Solid(color), | 63 | pattern: Pattern::Solid(color), |
56 | dash: None, | 64 | dash: None, |
57 | line_width: Float::Fixed(0.), | 65 | line_width: None, |
58 | } | 66 | } |
59 | } | 67 | } |
60 | 68 | ||
61 | pub fn builder() -> StrokeStyleBuilder { | 69 | pub fn builder() -> StrokeStyleBuilder { |
62 | StrokeStyleBuilder::default() | 70 | StrokeStyleBuilder::default() |
63 | } | 71 | } |
72 | |||
73 | pub fn pattern(&self) -> Pattern { | ||
74 | self.pattern | ||
75 | } | ||
76 | |||
77 | pub fn set_pattern(&mut self, pattern: Pattern) { | ||
78 | self.pattern = pattern; | ||
79 | } | ||
80 | |||
81 | pub fn dash(&self) -> Option<&DashStyle> { | ||
82 | self.dash.as_ref() | ||
83 | } | ||
84 | |||
85 | pub fn set_dash(&mut self, dash: Option<DashStyle>) { | ||
86 | self.dash = dash; | ||
87 | } | ||
88 | |||
89 | pub fn line_width(&self) -> Option<Float> { | ||
90 | self.line_width | ||
91 | } | ||
92 | |||
93 | pub fn set_line_width(&mut self, line_width: Option<Float>) { | ||
94 | self.line_width = line_width; | ||
95 | } | ||
64 | } | 96 | } |
65 | 97 | ||
66 | impl Default for StrokeStyle { | 98 | impl Default for StrokeStyle { |
@@ -96,15 +128,12 @@ impl StrokeStyleBuilder { | |||
96 | StrokeStyle { | 128 | StrokeStyle { |
97 | pattern: self.pattern.unwrap_or_default(), | 129 | pattern: self.pattern.unwrap_or_default(), |
98 | dash: self.dash.clone(), | 130 | dash: self.dash.clone(), |
99 | line_width: self.line_width.unwrap_or(Float::Fixed(2.)), | 131 | line_width: self.line_width, |
100 | } | 132 | } |
101 | } | 133 | } |
102 | 134 | ||
103 | } | 135 | } |
104 | 136 | ||
105 | |||
106 | |||
107 | |||
108 | #[derive(Clone, Debug, Default)] | 137 | #[derive(Clone, Debug, Default)] |
109 | pub struct DashStyle { | 138 | pub struct DashStyle { |
110 | pub(crate) dashes: Vec<Float>, | 139 | pub(crate) dashes: Vec<Float>, |