A simple CPU rendered GUI IDE experience.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::ops::Deref;

use dsb::Cell;

#[derive(serde::Serialize, serde::Deserialize)]
pub struct CellBuffer {
    pub c: usize,
    pub vo: usize,
    pub cells: Box<[Cell]>,
}
impl std::fmt::Debug for CellBuffer {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("CellBuffer")
            .field("c", &self.c)
            .field("vo", &self.vo)
            .field("cells", &self.cells.len())
            .finish()
    }
}
impl Deref for CellBuffer {
    type Target = [Cell];

    fn deref(&self) -> &Self::Target {
        &self.cells
    }
}

impl CellBuffer {
    pub fn displayable(&self, r: usize) -> &[Cell] {
        &self[self.vo * self.c..((self.vo + r) * self.c).min(self.len())]
    }
    pub fn l(&self) -> usize {
        self.len() / self.c
    }
}