draw_line method added to framebuffer

This commit is contained in:
Cooper Quintin
2024-06-13 17:20:25 -07:00
parent 8365cb5706
commit e31bccb229
2 changed files with 24 additions and 1 deletions

View File

@@ -146,7 +146,9 @@ async fn update_ui(task_tracker: &TaskTracker, config: &config::Config, mut ui_
Err(e) => panic!("error receiving shutdown message: {e}")
}
if img_name.ends_with(".gif"){
if img_name == "subtle.png" {
fb.draw_line(framebuffer::Color565::Green, 2);
} else if img_name.ends_with(".gif"){
fb.draw_gif(img.contents());
} else {
fb.draw_img(img.contents());

View File

@@ -11,6 +11,17 @@ struct Dimensions {
width: u32,
}
#[allow(dead_code)]
pub enum Color565 {
Red = 0b1111100000000000,
Green = 0b0000011111100000,
Blue = 0b0000000000011111,
White = 0b1111111111111111,
Black = 0b0000000000000000,
Cyan = 0b0000011111111111,
Yellow = 0b1111111111100000,
}
#[derive(Copy, Clone)]
pub struct Framebuffer<'a> {
dimensions: Dimensions,
@@ -70,4 +81,14 @@ impl Framebuffer<'_>{
let img = image::load_from_memory(img_buffer).unwrap();
self.write(img);
}
pub fn draw_line(&mut self, color: Color565, height: u32){
let px_num= height * self.dimensions.width;
let color: u16 = color as u16;
let mut buffer: Vec<u8> = Vec::new();
for _ in 0..px_num {
buffer.extend(color.to_le_bytes());
}
std::fs::write(self.path, &buffer).unwrap();
}
}