Skip to content

Commit

Permalink
✨ Implement RenderCSS for all Option<T: RenderCSS>
Browse files Browse the repository at this point in the history
  • Loading branch information
ewen-lbh committed May 5, 2024
1 parent 25d66b7 commit 7f1c59b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,3 @@ impl Fill {
}
}

impl RenderCSS for Option<Fill> {
fn render_fill_css(&self, colormap: &ColorMapping) -> String {
self.map(|fill| fill.render_fill_css(colormap))
.unwrap_or_default()
}

fn render_stroke_css(&self, colormap: &ColorMapping) -> String {
self.map(|fill| fill.render_stroke_css(colormap))
.unwrap_or_default()
}
}
14 changes: 14 additions & 0 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ pub trait RenderCSS {
}
}

impl<T: RenderCSS> RenderCSS for Option<T> {
fn render_fill_css(&self, colormap: &ColorMapping) -> String {
self.as_ref()
.map(|v| v.render_fill_css(colormap))
.unwrap_or_default()
}

fn render_stroke_css(&self, colormap: &ColorMapping) -> String {
self.as_ref()
.map(|v| v.render_stroke_css(colormap))
.unwrap_or_default()
}
}

impl Object {
pub fn translate(&mut self, dx: i32, dy: i32) {
match self {
Expand Down

0 comments on commit 7f1c59b

Please sign in to comment.