rlvgl_platform/
display.rs1use alloc::vec;
3use alloc::vec::Vec;
4use rlvgl_core::widget::{Color, Rect};
5
6pub trait DisplayDriver {
8 fn flush(&mut self, area: Rect, colors: &[Color]);
10
11 fn vsync(&mut self) {}
13}
14
15pub struct DummyDisplay;
17
18impl DisplayDriver for DummyDisplay {
19 fn flush(&mut self, _area: Rect, _colors: &[Color]) {}
20}
21
22pub struct BufferDisplay {
24 pub width: usize,
26 pub height: usize,
28 pub buffer: Vec<Color>,
30}
31
32impl BufferDisplay {
33 pub fn new(width: usize, height: usize) -> Self {
35 Self {
36 width,
37 height,
38 buffer: vec![Color(0, 0, 0, 255); width * height],
39 }
40 }
41}
42
43impl DisplayDriver for BufferDisplay {
44 fn flush(&mut self, area: Rect, colors: &[Color]) {
45 for y in 0..area.height as usize {
46 for x in 0..area.width as usize {
47 let idx = (area.y as usize + y) * self.width + (area.x as usize + x);
48 self.buffer[idx] = colors[y * area.width as usize + x];
49 }
50 }
51 }
52}