add fill option to rectangle canvas struct

pull/453/head
Valerio 3 years ago
parent 8832281dcf
commit 41b1af5058

@ -37,6 +37,7 @@ impl App {
width: 10.0,
height: 10.0,
color: Color::Yellow,
fill: false
},
playground: Rect::new(10, 10, 100, 100),
vx: 1.0,

@ -345,6 +345,7 @@ where
width: 10.0,
height: 10.0,
color: Color::Yellow,
fill: false
});
for (i, s1) in app.servers.iter().enumerate() {
for s2 in &app.servers[i + 1..] {

@ -11,40 +11,63 @@ pub struct Rectangle {
pub width: f64,
pub height: f64,
pub color: Color,
pub fill: bool
}
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,
},
];
let mut lines: Vec<Line> = Vec::new();
if !self.fill {
lines = [
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,
},
].to_vec();
}else{
let mut n: f64 = 0.0;
while n < self.height {
lines.push(Line{
x1: self.x,
y1: self.y + n,
x2: self.x + self.width,
y2: self.y + n,
color: self.color
});
n += 0.5
}
}
for line in &lines {
line.draw(painter);
}

Loading…
Cancel
Save