Files
Graphite/core/document/src/layers/rect.rs
TrueDoctor fc10575dfa Improve rendering efficiency and add caching (#95)
Fixes #84

*Reduce heap allocations
* Add caching for rendering svgs
* Deduplicate UpdateCanvas Responses
2021-05-02 21:21:39 +02:00

34 lines
641 B
Rust

use super::style;
use super::LayerData;
use std::fmt::Write;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Rect {
shape: kurbo::Rect,
style: style::PathStyle,
}
impl Rect {
pub fn new(p0: impl Into<kurbo::Point>, p1: impl Into<kurbo::Point>, style: style::PathStyle) -> Rect {
Rect {
shape: kurbo::Rect::from_points(p0, p1),
style,
}
}
}
impl LayerData for Rect {
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(),
);
}
}