This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

✨ Make solid fills work on RawSVG shapes

See #94

+39 -20
+8 -4
src/graphics/shapes.rs
··· 24 24 // FittedText(Region, String), 25 25 Rectangle(Point, Point), 26 26 Image(Region, String), 27 - RawSVG(String), 27 + RawSVG { 28 + content: String, 29 + /// String to search & replace in the SVG content when applying a color fill to the shape (see `Object`). For example, `#c0ffee`. 30 + color: String, 31 + }, 28 32 // Tiling(Region, Box<Object>), 29 33 Component { 30 34 at: Point, ··· 62 66 BigCircle(center) | SmallCircle(center) => center.translate(dx, dy), 63 67 Image(region, ..) => region.translate(dx, dy), 64 68 Component { at, .. } => at.translate(dx, dy), 65 - RawSVG(_) => { 69 + RawSVG { .. } => { 66 70 unimplemented!() 67 71 } 68 72 } ··· 83 87 | SmallCircle(at) 84 88 | Component { at, .. } 85 89 | Image(Region { start: at, .. }, ..) => *at, 86 - RawSVG(_) => { 90 + RawSVG { .. } => { 87 91 unimplemented!() 88 92 } 89 93 } ··· 154 158 Image(region, ..) => *region, 155 159 Component { at, size, .. } => Region::from_topleft(*at, *size) 156 160 .expect("Invalid region for component"), 157 - RawSVG(_) => { 161 + RawSVG { .. } => { 158 162 unimplemented!() 159 163 } 160 164 }
+28 -7
src/rendering/objects.rs
··· 1 1 use itertools::Itertools; 2 2 use measure_time::debug_time; 3 3 4 - use crate::Object; 4 + use crate::{Fill, Object, Shape}; 5 5 6 6 use super::{ 7 7 CSSRenderable, SVGAttributesRenderable, renderable::SVGRenderable, svg, ··· 16 16 id: &str, 17 17 ) -> anyhow::Result<svg::Node> { 18 18 debug_time!("render_to_svg/colored_object"); 19 - let plain_obj = self.shape.render_to_svg( 20 - colormap.clone(), 21 - cell_size, 22 - object_sizes, 23 - id, 24 - )?; 19 + 20 + let plain_obj = match &self.shape { 21 + Shape::RawSVG {..} => self.render_raw_svg(&colormap), 22 + _ => self.shape.render_to_svg( 23 + colormap.clone(), 24 + cell_size, 25 + object_sizes, 26 + id, 27 + )?, 28 + }; 25 29 26 30 let mut css = self 27 31 .fill ··· 73 77 } 74 78 } 75 79 } 80 + 81 + impl Object { 82 + fn render_raw_svg(&self, colormap: &crate::ColorMapping) -> svg::Node { 83 + if let Shape::RawSVG { content, color } = &self.shape { 84 + let filled_svg = match &self.fill { 85 + Some(Fill::Solid(fill_color)) => { 86 + content.replace(color, &fill_color.render(colormap)) 87 + } 88 + _ => content.clone(), 89 + }; 90 + 91 + svg::Node::SVG(filled_svg) 92 + } else { 93 + panic!("Called render_raw_svg on a non-RawSVG shape"); 94 + } 95 + } 96 + }
+3 -9
src/rendering/shapes.rs
··· 33 33 Shape::Component { .. } => { 34 34 self.render_component(colormap, cell_size, object_sizes, id) 35 35 } 36 - Shape::RawSVG(..) => self.render_raw_svg(), 36 + Shape::RawSVG { .. } => { 37 + unimplemented!("RawSVG shapes require an Object to render") 38 + } 37 39 }; 38 40 39 41 Ok(match rendered { ··· 113 115 } 114 116 115 117 panic!("Expected Component, got {:?}", self); 116 - } 117 - 118 - fn render_raw_svg(&self) -> svg::Node { 119 - if let Shape::RawSVG(svg) = self { 120 - return svg::Node::SVG(svg.clone()); 121 - } 122 - 123 - panic!("Expected RawSVG, got {:?}", self); 124 118 } 125 119 126 120 fn render_text(&self, cell_size: usize) -> svg::Node {