1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use image::Rgba;
use crate::colors::{self, Color};
#[derive(Clone)]
pub struct Rect {
position: (u32, u32),
size: (u32, u32),
color: Color,
}
impl Rect {
pub fn new() -> Rect {
Rect {
position: (0, 0),
size: (10, 10),
color: colors::GREEN,
}
}
pub fn position(&mut self, x: u32, y: u32) -> Self {
self.position = (x, y);
self.clone()
}
pub fn size(&mut self, width: u32, height: u32) -> Self {
self.size = (width, height);
self.clone()
}
pub fn color(&mut self, color: Color) -> Self {
self.color = color;
self.clone()
}
}
pub struct RectValues {
pub x: i32,
pub y: i32,
pub width: u32,
pub height: u32,
pub color: Rgba<u8>,
}
pub fn extract(rect: &Rect) -> RectValues {
RectValues {
x: rect.position.0 as i32,
y: rect.position.1 as i32,
width: rect.size.0,
height: rect.size.1,
color: Rgba(rect.color),
}
}