From 4fdd5280f1e79ea6575a6a110951c564a7dd235e Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Sat, 4 Jun 2016 19:40:30 -0700 Subject: Add iterator methods to Grid and Row types The iterator methods simplify logic in the main grid render function. To disambiguate iterator methods from those returning counts (and to free up names), the `rows()` and `cols()` methods on `Grid` have been renamed to `num_rows()` and `num_cols()`, respectively. --- src/renderer/mod.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/renderer') diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index c983beba..2ba5b94c 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -182,17 +182,21 @@ impl QuadRenderer { pub fn render_grid(&mut self, grid: &Grid, glyph_cache: &GlyphCache, props: &TermProps) { self.prepare_render(props); - for i in 0..grid.rows() { - let row = &grid[i]; - for j in 0..row.cols() { - let cell = &row[j]; - if cell.c != ' ' { - if let Some(glyph) = glyph_cache.get(&cell.c) { - self.render(glyph, i as f32, j as f32, &cell.fg, cell.c); - } + + for (i, row) in grid.rows().enumerate() { + for (j, cell) in row.cells().enumerate() { + // Skip empty cells + if cell.c == ' ' { + continue; + } + + // Render if glyph is loaded + if let Some(glyph) = glyph_cache.get(&cell.c) { + self.render(glyph, i as f32, j as f32, &cell.fg, cell.c); } } } + self.finish_render(); } -- cgit