dashboard/mode/
startup.rs1use embedded_graphics::{
2 pixelcolor::Rgb666,
3 prelude::{Point, RgbColor, Size, WebColors},
4 primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
5};
6
7use crate::display_mod::{DISPLAY_HEIGHT, DISPLAY_WIDTH, DisplayDevice};
8
9fn linear_gradient(
10 start_color: Rgb666,
11 end_color: Rgb666,
12 index: u32,
13 gradient_width: u32,
14) -> Rgb666 {
15 let t = index as f32 / gradient_width as f32;
16 let interpolate_color =
17 |start: u8, end: u8| (start as f32 + (t * (end as f32 - start as f32))) as u8;
18
19 Rgb666::new(
20 interpolate_color(start_color.r(), end_color.r()),
21 interpolate_color(start_color.g(), end_color.g()),
22 interpolate_color(start_color.b(), end_color.b()),
23 )
24}
25
26fn render_linear_gradient(
27 display: &mut DisplayDevice,
28 start_color: Rgb666,
29 end_color: Rgb666,
30 start_column: usize,
31 gradient_width: u32,
32) {
33 for i in 0..gradient_width {
34 let column_color = linear_gradient(start_color, end_color, i, gradient_width);
35 let column_rect = Rectangle::new(
36 Point::new(i as i32 + start_column as i32, 0),
37 Size::new(1, DISPLAY_HEIGHT),
38 );
39 let column_style = PrimitiveStyle::with_fill(column_color);
40
41 column_rect.draw_styled(&column_style, display).unwrap();
42 }
43}
44
45pub fn render_startup_gui(display: &mut DisplayDevice) {
46 let colors = [
47 Rgb666::RED,
48 Rgb666::CSS_ORANGE,
49 Rgb666::CSS_YELLOW,
50 Rgb666::GREEN,
51 Rgb666::CYAN,
52 Rgb666::BLUE,
53 Rgb666::CSS_INDIGO,
54 Rgb666::CSS_PURPLE,
55 Rgb666::CSS_VIOLET,
56 ];
57 let gradient_width = DISPLAY_WIDTH / (colors.len() as u32 - 1);
58 for column in 0..(colors.len() - 1) {
59 render_linear_gradient(
60 display,
61 colors[column],
62 colors[column + 1],
63 column * gradient_width as usize,
64 gradient_width,
65 );
66 }
67}