use crate::*; pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut Cell, u16, u16)) { for row in 0..area.h() { let y = area.y() + row; for col in 0..area.w() { let x = area.x() + col; if x < buf.area.width && y < buf.area.height { callback(buf.get_mut(x, y), col, row); } } } } #[derive(Default)] pub struct BigBuffer { pub width: usize, pub height: usize, pub content: Vec } impl BigBuffer { pub fn new (width: usize, height: usize) -> Self { Self { width, height, content: vec![Cell::default(); width*height] } } pub fn get (&self, x: usize, y: usize) -> Option<&Cell> { let i = self.index_of(x, y); self.content.get(i) } pub fn get_mut (&mut self, x: usize, y: usize) -> Option<&mut Cell> { let i = self.index_of(x, y); self.content.get_mut(i) } pub fn index_of (&self, x: usize, y: usize) -> usize { y * self.width + x } } from!(|size:(usize, usize)| BigBuffer = Self::new(size.0, size.1));