MCPcopy Index your code
hub / github.com/endbasic/endbasic / new

Method new

std/src/gfx/lcd/buffered/mod.rs:59–96  ·  view source on GitHub ↗

Creates a new buffered LCD backed by `lcd`.

(lcd: L, font: &'static Font)

Source from the content-addressed store, hash-verified

57{
58 /// Creates a new buffered LCD backed by `lcd`.
59 pub fn new(lcd: L, font: &'static Font) -> Self {
60 let (size, stride) = lcd.info();
61
62 let fb = {
63 let pixels = size.width * size.height;
64 vec![0; pixels * stride]
65 };
66
67 let size_chars = font.chars_in_area(size.into());
68
69 // Precompute the table of encoded ANSI colors. This is necessary for O(1) decoding
70 // of rendered pixels.
71 let ansi_colors = {
72 let mut ansi_colors = HashMap::new();
73 for color in u8::MIN..=u8::MAX {
74 let pixel = lcd.encode(ansi_color_to_rgb(color));
75 ansi_colors.entry(pixel.as_slice().to_vec()).or_insert(color);
76 }
77 ansi_colors
78 };
79
80 let draw_color = lcd.encode((255, 255, 255));
81 let row_buffer = Vec::with_capacity(size.width * stride);
82
83 Self {
84 lcd,
85 font,
86 fb,
87 stride,
88 sync: true,
89 damage: None,
90 size_pixels: size,
91 size_chars,
92 ansi_colors,
93 draw_color,
94 row_buffer,
95 }
96 }
97
98 /// Executes mutations on the buffered LCD via `ops` while ensuring that syncing is disabled.
99 fn without_sync<O>(&mut self, ops: O) -> io::Result<()>

Callers

nothing calls this directly

Calls 5

ansi_color_to_rgbFunction · 0.85
chars_in_areaMethod · 0.80
infoMethod · 0.45
encodeMethod · 0.45
as_sliceMethod · 0.45

Tested by

no test coverage detected