Implement Line tool (#71)

* Add Line tool
This commit is contained in:
Edwin Cheng
2021-04-13 12:43:05 +08:00
committed by GitHub
parent 8c957e572b
commit 1fd298cf9e
7 changed files with 92 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
pub mod operation;
pub use kurbo::{Circle, Point, Rect};
pub use kurbo::{Circle, Line, Point, Rect};
pub use operation::Operation;
#[derive(Debug, Clone, PartialEq)]
@@ -8,6 +8,7 @@ pub enum LayerType {
Folder(Folder),
Circle(Circle),
Rect(Rect),
Line(Line),
}
impl LayerType {
@@ -20,6 +21,9 @@ impl LayerType {
Self::Rect(r) => {
format!(r#"<rect x="{}" y="{}" width="{}" height="{}" style="fill: #fff;" />"#, r.min_x(), r.min_y(), r.width(), r.height())
}
Self::Line(l) => {
format!(r#"<line x1="{}" y1="{}" x2="{}" y2="{}" style="stroke: #fff;" />"#, l.p0.x, l.p0.y, l.p1.x, l.p1.y)
}
}
}
}
@@ -211,6 +215,11 @@ impl Document {
update_frontend(self.render());
}
Operation::AddLine { path, insert_index, x0, y0, x1, y1 } => {
self.add_layer(&path, Layer::new(LayerType::Line(Line::new(Point::new(x0, y0), Point::new(x1, y1)))), insert_index)?;
update_frontend(self.render());
}
Operation::DeleteLayer { path } => {
self.delete(&path)?;

View File

@@ -16,6 +16,14 @@ pub enum Operation {
x1: f64,
y1: f64,
},
AddLine {
path: Vec<LayerId>,
insert_index: isize,
x0: f64,
y0: f64,
x1: f64,
y1: f64,
},
DeleteLayer {
path: Vec<LayerId>,
},