aboutsummaryrefslogtreecommitdiffstats
path: root/src/ratatui/widgets/canvas/rectangle.rs
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-03-31 22:57:37 +0100
committerGitHub <noreply@github.com>2023-03-31 22:57:37 +0100
commita515b06bcb556c1be2d0fc3095cd778d413fe40d (patch)
tree4b544de9aa53d6976177c08b91aa3943ef4d9e92 /src/ratatui/widgets/canvas/rectangle.rs
parentfeat: add github action to test the nix builds (#833) (diff)
downloadatuin-a515b06bcb556c1be2d0fc3095cd778d413fe40d.zip
Vendor ratatui temporarily (#835)
* Vendor ratatui temporarily Once https://github.com/tui-rs-revival/ratatui/pull/114 has been merged, we can undo this! But otherwise we can't publish to crates.io with a git dependency. * make tests pass * Shush. * these literally just fail in nix, nowhere else idk how to work with nix properly, and they're also not our tests
Diffstat (limited to '')
-rw-r--r--src/ratatui/widgets/canvas/rectangle.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/ratatui/widgets/canvas/rectangle.rs b/src/ratatui/widgets/canvas/rectangle.rs
new file mode 100644
index 00000000..07ac9137
--- /dev/null
+++ b/src/ratatui/widgets/canvas/rectangle.rs
@@ -0,0 +1,52 @@
+use crate::ratatui::{
+ style::Color,
+ widgets::canvas::{Line, Painter, Shape},
+};
+
+/// Shape to draw a rectangle from a `Rect` with the given color
+#[derive(Debug, Clone)]
+pub struct Rectangle {
+ pub x: f64,
+ pub y: f64,
+ pub width: f64,
+ pub height: f64,
+ pub color: Color,
+}
+
+impl Shape for Rectangle {
+ fn draw(&self, painter: &mut Painter) {
+ let lines: [Line; 4] = [
+ Line {
+ x1: self.x,
+ y1: self.y,
+ x2: self.x,
+ y2: self.y + self.height,
+ color: self.color,
+ },
+ Line {
+ x1: self.x,
+ y1: self.y + self.height,
+ x2: self.x + self.width,
+ y2: self.y + self.height,
+ color: self.color,
+ },
+ Line {
+ x1: self.x + self.width,
+ y1: self.y,
+ x2: self.x + self.width,
+ y2: self.y + self.height,
+ color: self.color,
+ },
+ Line {
+ x1: self.x,
+ y1: self.y,
+ x2: self.x + self.width,
+ y2: self.y,
+ color: self.color,
+ },
+ ];
+ for line in &lines {
+ line.draw(painter);
+ }
+ }
+}