altui_core/widgets/canvas/
rectangle.rs1use crate::{
2 style::Color,
3 widgets::canvas::{Line, Painter, Shape},
4};
5
6#[derive(Debug, Clone)]
8pub struct Rectangle {
9 pub x: f64,
10 pub y: f64,
11 pub width: f64,
12 pub height: f64,
13 pub color: Color,
14}
15
16impl Shape for Rectangle {
17 fn draw(&self, painter: &mut Painter) {
18 let lines: [Line; 4] = [
19 Line {
20 x1: self.x,
21 y1: self.y,
22 x2: self.x,
23 y2: self.y + self.height,
24 color: self.color,
25 },
26 Line {
27 x1: self.x,
28 y1: self.y + self.height,
29 x2: self.x + self.width,
30 y2: self.y + self.height,
31 color: self.color,
32 },
33 Line {
34 x1: self.x + self.width,
35 y1: self.y,
36 x2: self.x + self.width,
37 y2: self.y + self.height,
38 color: self.color,
39 },
40 Line {
41 x1: self.x,
42 y1: self.y,
43 x2: self.x + self.width,
44 y2: self.y,
45 color: self.color,
46 },
47 ];
48 for line in &lines {
49 line.draw(painter);
50 }
51 }
52}