More refactor, exposing some interface to graphics

This commit is contained in:
JP Stringham
2025-12-28 10:46:33 -05:00
parent 0c4347879b
commit abb6d9983e
2 changed files with 13 additions and 12 deletions

View File

@@ -45,24 +45,22 @@ impl GraphicsBuf {
} }
}); });
self.sprite_atlas
.draw_string(10, 10, "Hello World!", &mut gfx_buf);
self.sprite_atlas.draw_textfield(
10,
20,
110,
10,
"I think this font has a *lot* of 'character'! ;)",
&mut gfx_buf,
);
draw_bresenham_line(0, 0, 127, 0, &mut gfx_buf); draw_bresenham_line(0, 0, 127, 0, &mut gfx_buf);
draw_bresenham_line(0, 63, 128, 63, &mut gfx_buf); draw_bresenham_line(0, 63, 128, 63, &mut gfx_buf);
draw_bresenham_line(0, 0, 0, 63, &mut gfx_buf); draw_bresenham_line(0, 0, 0, 63, &mut gfx_buf);
draw_bresenham_line(127, 0, 127, 63, &mut gfx_buf); draw_bresenham_line(127, 0, 127, 63, &mut gfx_buf);
} }
pub fn draw_string(&mut self, x: u8, y: u8, string: &str) {
self.sprite_atlas
.draw_string(x, y, string, &mut self.buffer);
}
pub fn draw_textfield(&mut self, x: u8, y: u8, width: u8, height: u8, string: &str) {
self.sprite_atlas
.draw_textfield(x, y, width, height, string, &mut self.buffer);
}
pub fn get_px_buffer(&self) -> &[u8; 8192] { pub fn get_px_buffer(&self) -> &[u8; 8192] {
&self.buffer &self.buffer
} }

View File

@@ -72,6 +72,9 @@ fn main() -> ! {
loop { loop {
gfx_buf.clear(); gfx_buf.clear();
gfx_buf.draw_textfield(10, 10, 100, 60, "Hello! This is a test. :)");
gfx_buf.redraw(); gfx_buf.redraw();
sh1106_dev.blit_framebuffer(&mut i2c, &gfx_buf); sh1106_dev.blit_framebuffer(&mut i2c, &gfx_buf);