From ef22c951f41eda98ca91bf74f9897b42509a804a Mon Sep 17 00:00:00 2001 From: daa84 Date: Tue, 12 Dec 2017 16:40:13 +0300 Subject: [PATCH] Fix #26 --- src/render/mod.rs | 78 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 3622a32..c33ebb6 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -34,6 +34,15 @@ pub fn render( let &CellMetrics { char_width, .. } = cell_metrics; let (cursor_row, cursor_col) = ui_model.get_cursor(); + for cell_view in ui_model.get_clip_iterator(ctx, cell_metrics) { + let mut line_x = 0.0; + + for (col, cell) in cell_view.line.line.iter().enumerate() { + draw_cell_bg(&cell_view, color_model, cell, col, line_x); + line_x += char_width; + } + } + for cell_view in ui_model.get_clip_iterator(ctx, cell_metrics) { let mut line_x = 0.0; let RowView { line, row, line_y, .. } = cell_view; @@ -44,7 +53,6 @@ pub fn render( draw_underline(&cell_view, color_model, cell, line_x); - if row == cursor_row && col == cursor_col { let double_width = line.line.get(col + 1).map_or( false, @@ -108,6 +116,48 @@ fn draw_underline( } } +fn draw_cell_bg( + cell_view: &RowView, + color_model: &color::ColorModel, + cell: &ui_model::Cell, + col: usize, + line_x: f64, +) { + let &RowView { + ctx, + line, + line_y, + cell_metrics: &CellMetrics { + char_width, + line_height, + .. + }, + .. + } = cell_view; + + let bg = color_model.cell_bg(cell); + + if let Some(bg) = bg { + if !line.is_binded_to_item(col) { + if bg != &color_model.bg_color { + ctx.set_source_rgb(bg.0, bg.1, bg.2); + ctx.rectangle(line_x, line_y, char_width, line_height); + ctx.fill(); + } + } else { + ctx.set_source_rgb(bg.0, bg.1, bg.2); + ctx.rectangle( + line_x, + line_y, + char_width * line.item_len_from_idx(col) as f64, + line_height, + ); + ctx.fill(); + } + } + +} + fn draw_cell( cell_view: &RowView, color_model: &color::ColorModel, @@ -121,43 +171,21 @@ fn draw_cell( line, line_y, cell_metrics: &CellMetrics { - char_width, - line_height, ascent, .. }, .. } = cell_view; - let (bg, fg) = color_model.cell_colors(cell); - if let Some(item) = line.item_line[col].as_ref() { - if let Some(bg) = bg { - ctx.set_source_rgb(bg.0, bg.1, bg.2); - ctx.rectangle( - line_x, - line_y, - char_width * line.item_len_from_idx(col) as f64, - line_height, - ); - ctx.fill(); - } - if let Some(ref glyphs) = item.glyphs { + let fg = color_model.actual_cell_fg(cell); + ctx.move_to(line_x, line_y + ascent); ctx.set_source_rgb(fg.0, fg.1, fg.2); ctx.show_glyph_string(item.font(), glyphs); } - } else if !line.is_binded_to_item(col) { - let bg = color_model.cell_bg(cell); - if let Some(bg) = bg { - if bg != &color_model.bg_color { - ctx.set_source_rgb(bg.0, bg.1, bg.2); - ctx.rectangle(line_x, line_y, char_width, line_height); - ctx.fill(); - } - } } }