use alloc::vec;
use alloc::vec::Vec;
use rlvgl_core::widget::{Color, Rect};
pub trait DisplayDriver {
fn flush(&mut self, area: Rect, colors: &[Color]);
fn vsync(&mut self) {}
}
pub struct DummyDisplay;
impl DisplayDriver for DummyDisplay {
fn flush(&mut self, _area: Rect, _colors: &[Color]) {}
}
pub struct BufferDisplay {
pub width: usize,
pub height: usize,
pub buffer: Vec<Color>,
}
impl BufferDisplay {
pub fn new(width: usize, height: usize) -> Self {
Self {
width,
height,
buffer: vec![Color(0, 0, 0, 255); width * height],
}
}
}
impl DisplayDriver for BufferDisplay {
fn flush(&mut self, area: Rect, colors: &[Color]) {
for y in 0..area.height as usize {
for x in 0..area.width as usize {
let idx = (area.y as usize + y) * self.width + (area.x as usize + x);
self.buffer[idx] = colors[y * area.width as usize + x];
}
}
}
}