Add ToolData and rectangle tool (#64)

This commit is contained in:
TrueDoctor
2021-04-07 09:25:23 +02:00
committed by Keavon Chambers
parent fafea371ab
commit 599d478a5c
7 changed files with 103 additions and 17 deletions

View File

@@ -1,11 +1,12 @@
pub mod operation;
pub use kurbo::{Circle, Point};
pub use kurbo::{Circle, Point, Rect};
pub use operation::Operation;
#[derive(Debug, Clone, PartialEq)]
pub enum SvgElement {
Circle(Circle),
Rect(Rect),
}
impl SvgElement {
@@ -14,6 +15,9 @@ impl SvgElement {
Self::Circle(c) => {
format!(r#"<circle cx="{}" cy="{}" r="{}" style="fill: #fff;" />"#, c.center.x, c.center.y, c.radius)
}
Self::Rect(r) => {
format!(r#"<rect x="{}" y="{}" width="{}" height="{}" style="fill: #fff;" />"#, r.min_x(), r.min_y(), r.width(), r.height())
}
}
}
}
@@ -36,6 +40,11 @@ impl Document {
radius: r,
}));
update_frontend(self.render());
}
Operation::AddRect { x0, y0, x1, y1 } => {
self.svg.push(SvgElement::Rect(Rect::from_points(Point::new(x0, y0), Point::new(x1, y1))));
update_frontend(self.render());
}
}

View File

@@ -1,3 +1,4 @@
pub enum Operation {
AddCircle { cx: f64, cy: f64, r: f64 },
AddRect { x0: f64, y0: f64, x1: f64, y1: f64 },
}