1use crate::shape::Shape;
3use crate::{DisplayList, Drawing};
4
5pub struct Canvas {
7 pub width: u32,
9 pub height: u32,
11 pub background: Option<Shape>,
13 pub display_list: DisplayList,
15}
16
17impl Canvas {
18 pub fn new(width: u32, height: u32) -> Canvas {
20 Canvas {
21 width,
22 height,
23 background: None,
24 display_list: DisplayList::new(),
25 }
26 }
27
28 pub fn with_background(width: u32, height: u32, background: Shape) -> Canvas {
30 Canvas {
31 width,
32 height,
33 background: Some(background),
34 display_list: DisplayList::new(),
35 }
36 }
37
38 pub fn drawings(&self) -> &Vec<Drawing> {
40 &self.display_list.drawings
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn with_background() {
50 let canvas = Canvas::with_background(
51 50,
52 50,
53 Shape::Rectangle {
54 width: 50,
55 height: 50,
56 },
57 );
58
59 assert!(canvas.background.is_some());
60 }
61}