Improve rendering efficiency and add caching (#95)

Fixes #84

*Reduce heap allocations
* Add caching for rendering svgs
* Deduplicate UpdateCanvas Responses
This commit is contained in:
TrueDoctor
2021-05-02 21:21:39 +02:00
committed by Keavon Chambers
parent 457c465342
commit fc10575dfa
14 changed files with 123 additions and 73 deletions

View File

@@ -1,6 +1,8 @@
use super::style;
use super::LayerData;
use std::fmt::Write;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Rect {
shape: kurbo::Rect,
@@ -17,14 +19,15 @@ impl Rect {
}
impl LayerData for Rect {
fn render(&self) -> String {
format!(
fn render(&mut self, svg: &mut String) {
let _ = write!(
svg,
r#"<rect x="{}" y="{}" width="{}" height="{}" {} />"#,
self.shape.min_x(),
self.shape.min_y(),
self.shape.width(),
self.shape.height(),
self.style.render(),
)
);
}
}