diff --git a/Cargo.toml b/Cargo.toml
index 8ce4063..46ee4c2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,7 @@ license = "MIT"
[dependencies]
plotters-backend = "0.3.7"
-gpui = { git = "https://github.com/zed-industries/zed" }
+gpui = { git = "https://github.com/huacnlee/zed" }
parking_lot = "0.12.3"
plotters = { version = "0.3.7", optional = true }
tracing = "0.1"
diff --git a/README.md b/README.md
index b284e1c..55aef38 100644
--- a/README.md
+++ b/README.md
@@ -33,9 +33,13 @@ provides interactivity and more stuff on top of plotters-gpui
## Show cases
-
-
-
+
+
+
+
+
+
+
## Performance
@@ -54,4 +58,3 @@ Enables the Metal Performance HUD.
```shell
MTL_HUD_ENABLED=1 cargo run ...
```
-
diff --git a/src/backend.rs b/src/backend.rs
index 3c54fdb..97b9f71 100644
--- a/src/backend.rs
+++ b/src/backend.rs
@@ -72,11 +72,19 @@ impl DrawingBackend for GpuiBackend<'_> {
let color = color_to_hsla(style.color());
if fill {
- let mut path = gpui::Path::new(upper_left);
- path.line_to(point(upper_left.x, bottom_right.y));
- path.line_to(bottom_right);
- path.line_to(point(bottom_right.x, upper_left.y));
- path.line_to(upper_left);
+ let mut builder = gpui::PathBuilder::fill();
+ builder.move_to(upper_left);
+ builder.line_to(point(upper_left.x, bottom_right.y));
+ builder.line_to(bottom_right);
+ builder.line_to(point(bottom_right.x, upper_left.y));
+ builder.line_to(upper_left);
+ let path = builder.build().map_err(|err| {
+ DrawingErrorKind::DrawingError(std::io::Error::new(
+ std::io::ErrorKind::Other,
+ err.to_string(),
+ ))
+ })?;
+
self.window.paint_path(path, color);
} else {
for (p1, p2) in [
@@ -129,10 +137,20 @@ impl DrawingBackend for GpuiBackend<'_> {
Some(start) => start,
None => return Ok(()),
};
- let mut path = gpui::Path::new(coord_to_point(self.bounds.origin, start));
+
+ let mut builder = gpui::PathBuilder::fill();
+ builder.move_to(coord_to_point(self.bounds.origin, start));
for point in iter {
- path.line_to(coord_to_point(self.bounds.origin, point));
+ builder.line_to(coord_to_point(self.bounds.origin, point));
}
+
+ let path = builder.build().map_err(|err| {
+ DrawingErrorKind::DrawingError(std::io::Error::new(
+ std::io::ErrorKind::Other,
+ err.to_string(),
+ ))
+ })?;
+
let color = color_to_hsla(style.color());
self.window.paint_path(path, color);
Ok(())
diff --git a/src/line.rs b/src/line.rs
index 1850da5..cabf5c0 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -1,4 +1,4 @@
-use gpui::{point, Hsla, Path, Pixels, Point, Window};
+use gpui::{px, Hsla, PathBuilder, Pixels, Point, Window};
use tracing::warn;
#[derive(Clone, Debug)]
@@ -50,29 +50,18 @@ impl Line {
return;
}
- let width = self.width;
-
- let (Some(first), Some(last)) = (self.points.first().copied(), self.points.last().copied())
- else {
+ let mut builder = PathBuilder::stroke(px(self.width.0));
+ let Some(first_p) = self.points.first() else {
return;
};
- let mut angle = f32::atan2(first.y.0 - last.y.0, first.x.0 - last.x.0);
- angle += std::f32::consts::FRAC_PI_2;
- let shift = point(width * f32::cos(angle), width * f32::sin(angle));
-
- let mut reversed_points = vec![first + shift];
- let mut path = Path::new(first);
- for &p in &self.points[1..] {
- path.line_to(p);
- reversed_points.push(p + shift);
+ builder.move_to(*first_p);
+ for p in self.points.iter().skip(1) {
+ builder.line_to(*p);
}
- // now do the reverse to close the path
- for p in reversed_points.into_iter().rev() {
- path.line_to(p);
+ if let Ok(path) = builder.build() {
+ window.paint_path(path, self.color);
}
-
- window.paint_path(path, self.color);
}
}