Fix underline rendering

This commit is contained in:
daa 2017-09-12 15:09:17 +03:00
parent 61fdb83427
commit 39db875b6f
4 changed files with 10 additions and 20 deletions

View File

@ -43,11 +43,6 @@ impl Context {
&self.state.font_desc &self.state.font_desc
} }
#[inline]
pub fn ascent(&self) -> f64 {
self.state.cell_metrics.ascent
}
#[inline] #[inline]
pub fn cell_metrics(&self) -> &CellMetrics { pub fn cell_metrics(&self) -> &CellMetrics {
&self.state.cell_metrics &self.state.cell_metrics

View File

@ -33,10 +33,10 @@ pub fn render(
char_width, char_width,
underline_position, underline_position,
underline_thickness, underline_thickness,
ascent,
.. ..
} = font_ctx.cell_metrics(); } = font_ctx.cell_metrics();
let mut line_y = 0.0; let mut line_y = 0.0;
let ascent = font_ctx.ascent();
let (cursor_row, cursor_col) = ui_model.get_cursor(); let (cursor_row, cursor_col) = ui_model.get_cursor();
for (row, line) in ui_model.model().iter().enumerate() { for (row, line) in ui_model.model().iter().enumerate() {
@ -78,21 +78,20 @@ pub fn render(
if cell.attrs.underline || cell.attrs.undercurl { if cell.attrs.underline || cell.attrs.undercurl {
if cell.attrs.undercurl { if cell.attrs.undercurl {
// TODO: properly draw undercurl //FIXME: don't repaint all lines on changes
let sp = color_model.actual_cell_sp(cell); let sp = color_model.actual_cell_sp(cell);
ctx.set_source_rgba(sp.0, sp.1, sp.2, 0.7); ctx.set_source_rgba(sp.0, sp.1, sp.2, 0.7);
let max_undercurl_height = (line_height - underline_position) * 2.0;
let undercurl_height = (underline_thickness * 4.0).min(max_undercurl_height);
let undercurl_y = line_y + underline_position - undercurl_height / 2.0;
ctx.show_error_underline( ctx.show_error_underline(
line_x, line_x,
line_y + underline_position, undercurl_y,
char_width, char_width,
underline_thickness * 5.0, undercurl_height
); );
//ctx.set_dash(&[4.0, 2.0], 0.0);
//ctx.set_line_width(underline_thickness);
//ctx.move_to(line_x, line_y + underline_position);
//ctx.line_to(line_x + char_width, line_y + underline_position);
//ctx.stroke();
//ctx.set_dash(&[], 0.0);
} else if cell.attrs.underline { } else if cell.attrs.underline {
ctx.set_source_rgb(fg.0, fg.1, fg.2); ctx.set_source_rgb(fg.0, fg.1, fg.2);
ctx.set_line_width(underline_thickness); ctx.set_line_width(underline_thickness);

View File

@ -158,10 +158,6 @@ impl Line {
self.item_line[start_cell] = Some(Item::new(new_item.clone(), end_cell - start_cell + 1)); self.item_line[start_cell] = Some(Item::new(new_item.clone(), end_cell - start_cell + 1));
} }
pub fn mark_dirty_cell(&mut self, idx: usize) {
self.line[idx].dirty = true;
}
pub fn get_item_mut(&mut self, cell_idx: usize) -> Option<&mut Item> { pub fn get_item_mut(&mut self, cell_idx: usize) -> Option<&mut Item> {
let item_idx = self.cell_to_item(cell_idx); let item_idx = self.cell_to_item(cell_idx);
if item_idx >= 0 { if item_idx >= 0 {

View File

@ -74,13 +74,13 @@ impl UiModel {
let mut changed_region = self.cur_point(); let mut changed_region = self.cur_point();
let line = &mut self.model[self.cur_row]; let line = &mut self.model[self.cur_row];
line.dirty_line = true; line.dirty_line = true;
line.mark_dirty_cell(self.cur_col);
let cell = &mut line[self.cur_col]; let cell = &mut line[self.cur_col];
cell.ch = text.chars().last().unwrap_or(' '); cell.ch = text.chars().last().unwrap_or(' ');
cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(Attrs::new); cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(Attrs::new);
cell.attrs.double_width = text.is_empty(); cell.attrs.double_width = text.is_empty();
cell.dirty = true;
self.cur_col += 1; self.cur_col += 1;
if self.cur_col >= self.columns { if self.cur_col >= self.columns {
self.cur_col -= 1; self.cur_col -= 1;