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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
use chargrid_render::{grid_2d::Grid, Blend, Coord, Frame, Rgb24, Size, ViewCell}; struct Cell { view_cell: Option<ViewCell>, depth: i8, } impl Cell { fn new() -> Self { Self { view_cell: None, depth: 0, } } } pub struct TestGrid { grid: Grid<Cell>, } impl TestGrid { pub fn new(size: Size) -> Self { Self { grid: Grid::new_fn(size, |_| Cell::new()), } } pub fn string_rows(&self) -> Vec<String> { let mut rows = Vec::new(); for y in 0..self.grid.height() { let mut string = String::new(); for x in 0..self.grid.width() { let cell = self.grid.get_checked(Coord::new(x as i32, y as i32)); if let Some(view_cell) = cell.view_cell.as_ref() { string.push(view_cell.character.unwrap_or(' ')); } else { string.push(' '); } } rows.push(string); } rows } } impl Frame for TestGrid { fn set_cell_absolute(&mut self, absolute_coord: Coord, absolute_depth: i8, absolute_cell: ViewCell) { if let Some(cell) = self.grid.get_mut(absolute_coord) { if absolute_depth >= cell.depth { cell.depth = absolute_depth; cell.view_cell = Some(absolute_cell); } } } fn blend_cell_background_absolute<B: Blend>( &mut self, _absolute_coord: Coord, _absolute_depth: i8, _rgb24: Rgb24, _alpha: u8, _blend: B, ) { } }