retroglyph_ui/draw/
primitives.rs1use retroglyph_core::color::Style;
5use retroglyph_core::grid::Rect;
6
7use crate::Surface;
8
9pub fn fill_rect(surface: &mut Surface<'_>, rect: Rect, ch: char, style: Style) {
16 surface.fill_rect(rect, ch, style);
17}
18
19#[cfg(test)]
20mod tests {
21 use retroglyph_core::grid::{Grid, Pos};
22
23 use super::*;
24
25 #[test]
26 fn fill_rect_overwrites_the_whole_rectangle() {
27 let area = Rect::new(0, 0, 6, 4);
28 let rect = Rect::new(1, 1, 4, 2);
29 let mut grid = Grid::new(6, 4);
30 fill_rect(
31 &mut Surface::new(&mut grid, area, 0),
32 rect,
33 '#',
34 Style::new(),
35 );
36
37 for y in 1..3 {
38 for x in 1..5 {
39 assert_eq!(grid[Pos::new(x, y)].glyph(), '#');
40 }
41 }
42 assert_eq!(grid[Pos::new(0, 0)].glyph(), ' ');
44 }
45}