use crate::{Cell, Pos, Shape, Surface, SymbolCell};
#[derive(Debug)]
pub(crate) struct NamedSymbol {
pub(crate) at: Pos,
pub(crate) cell: SymbolCell,
}
impl Shape for NamedSymbol {
fn draw(&self, surface: &mut dyn Surface) {
surface.stamp(self.at, Cell::Symbol(self.cell.clone()));
}
}
#[cfg(test)]
mod tests {
use super::NamedSymbol;
use crate::{
Buffer, Cell, CellReader, FigureLayer, Pos, Shape, Size, StampMode, Symbol, SymbolCell,
SymbolStyleName, Window,
};
#[test]
fn a_named_symbol_writes_its_pair_as_a_symbol_cell() {
let mut buffer = Buffer::new(Window {
origin: Pos { x: 0, y: 0 },
size: Size {
width: 1,
height: 1,
},
});
let mut layer = FigureLayer::new(&mut buffer, StampMode::Above);
let cell = SymbolCell {
symbol: Symbol::DirectionUp,
style: SymbolStyleName::from("solid"),
};
NamedSymbol {
at: Pos { x: 0, y: 0 },
cell: cell.clone(),
}
.draw(&mut layer);
assert_eq!(buffer.cell(Pos { x: 0, y: 0 }), Some(&Cell::Symbol(cell)));
}
}