From b980a73988e3d61bf7fa8a7a7dd2c4c241535a4f Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 4 Jan 2023 09:36:12 +0100 Subject: core: make line_width optional, add CoreStyle accessors --- core/src/solving.rs | 7 ++++++- 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 { None => None, }; + let line_width = match self.line_width { + Some(f) => f.fixate(model)?, + None => 2., + }; + Some(DefinedStrokeStyle { pattern: self.pattern, dash, - line_width: self.line_width.fixate(model)?, + line_width, }) } } 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 { pattern: Pattern::Solid(color), } } + + pub fn pattern(&self) -> Pattern { + self.pattern + } + + pub fn set_pattern(&mut self, pattern: Pattern) { + self.pattern = pattern; + } } impl Default for FillStyle { @@ -46,7 +54,7 @@ impl Default for FillStyle { pub struct StrokeStyle { pub(crate) pattern: Pattern, pub(crate) dash: Option, - pub(crate) line_width: Float, + pub(crate) line_width: Option, } impl StrokeStyle { @@ -54,13 +62,37 @@ impl StrokeStyle { StrokeStyle { pattern: Pattern::Solid(color), dash: None, - line_width: Float::Fixed(0.), + line_width: None, } } pub fn builder() -> StrokeStyleBuilder { StrokeStyleBuilder::default() } + + pub fn pattern(&self) -> Pattern { + self.pattern + } + + pub fn set_pattern(&mut self, pattern: Pattern) { + self.pattern = pattern; + } + + pub fn dash(&self) -> Option<&DashStyle> { + self.dash.as_ref() + } + + pub fn set_dash(&mut self, dash: Option) { + self.dash = dash; + } + + pub fn line_width(&self) -> Option { + self.line_width + } + + pub fn set_line_width(&mut self, line_width: Option) { + self.line_width = line_width; + } } impl Default for StrokeStyle { @@ -96,15 +128,12 @@ impl StrokeStyleBuilder { StrokeStyle { pattern: self.pattern.unwrap_or_default(), dash: self.dash.clone(), - line_width: self.line_width.unwrap_or(Float::Fixed(2.)), + line_width: self.line_width, } } } - - - #[derive(Clone, Debug, Default)] pub struct DashStyle { pub(crate) dashes: Vec, -- cgit v1.2.3