Only draw differences from previous frame

This commit is contained in:
Joscha 2022-05-21 23:38:37 +02:00
parent 9512ddaa3b
commit 67f8919630
2 changed files with 12 additions and 11 deletions

View file

@ -30,7 +30,7 @@ impl Pos {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Cell {
pub content: Box<str>,
pub style: ContentStyle,
@ -67,6 +67,12 @@ impl Buffer {
y * width + x
}
pub(crate) fn at(&self, x: u16, y: u16) -> &Cell {
assert!(x < self.size.width);
assert!(y < self.size.height);
&self.data[self.index(x, y)]
}
pub fn size(&self) -> Size {
self.size
}
@ -143,14 +149,6 @@ pub struct Cells<'a> {
y: u16,
}
impl<'a> Cells<'a> {
fn at(&self, x: u16, y: u16) -> &'a Cell {
assert!(x < self.buffer.size.width);
assert!(y < self.buffer.size.height);
&self.buffer.data[self.buffer.index(x, y)]
}
}
impl<'a> Iterator for Cells<'a> {
type Item = (u16, u16, &'a Cell);
@ -160,7 +158,7 @@ impl<'a> Iterator for Cells<'a> {
}
let (x, y) = (self.x, self.y);
let cell = self.at(self.x, self.y);
let cell = self.buffer.at(self.x, self.y);
assert!(cell.offset == 0);
self.x += cell.width as u16;