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
use crate::{color::Color, math::Extent, DynScreen, Gpu, Input, Render, Screen};

/// Displays a solid color forever.
pub struct Solid {
    color: Color,
}

impl Solid {
    /// Constructs a new `Solid` from the given color.
    pub fn new(color: Color) -> Self {
        Self { color }
    }
}

impl Screen for Solid {
    fn render(&self, gpu: &Gpu, _: Extent) -> Render {
        let mut frame = gpu.render(
            #[cfg(feature = "debug-names")]
            &format!("Solid {}", self.color.to_hex()),
            Extent::new(8, 8),
        );
        frame
            .clear(
                #[cfg(feature = "debug-names")]
                "Solid",
            )
            .with_value(self.color)
            .record();

        frame
    }

    fn update(self: Box<Self>, _: &Gpu, _: &Input) -> DynScreen {
        self
    }
}