Merge branch 'fix-render-clip'

This commit is contained in:
daa 2017-12-21 21:09:10 +03:00
commit f5c86868fe
2 changed files with 53 additions and 39 deletions

View File

@ -64,20 +64,6 @@ impl ColorModel {
}
}
pub fn cell_colors<'a>(&'a self, cell: &'a Cell) -> (Option<&'a Color>, &'a Color) {
if !cell.attrs.reverse {
(
cell.attrs.background.as_ref(),
cell.attrs.foreground.as_ref().unwrap_or(&self.fg_color),
)
} else {
(
cell.attrs.foreground.as_ref().or(Some(&self.fg_color)),
cell.attrs.background.as_ref().unwrap_or(&self.bg_color),
)
}
}
pub fn cell_fg<'a>(&'a self, cell: &'a Cell) -> Option<&'a Color> {
if !cell.attrs.reverse {
cell.attrs.foreground.as_ref()

View File

@ -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();
}
}
}
}