diff --git a/src/render/context.rs b/src/render/context.rs index 74eb7bb..d2864fd 100644 --- a/src/render/context.rs +++ b/src/render/context.rs @@ -43,11 +43,6 @@ impl Context { &self.state.font_desc } - #[inline] - pub fn ascent(&self) -> f64 { - self.state.cell_metrics.ascent - } - #[inline] pub fn cell_metrics(&self) -> &CellMetrics { &self.state.cell_metrics diff --git a/src/render/mod.rs b/src/render/mod.rs index 21e6416..1b1797a 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -33,10 +33,10 @@ pub fn render( char_width, underline_position, underline_thickness, + ascent, .. } = font_ctx.cell_metrics(); let mut line_y = 0.0; - let ascent = font_ctx.ascent(); let (cursor_row, cursor_col) = ui_model.get_cursor(); 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.undercurl { - // TODO: properly draw undercurl + //FIXME: don't repaint all lines on changes let sp = color_model.actual_cell_sp(cell); 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( line_x, - line_y + underline_position, + undercurl_y, 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 { ctx.set_source_rgb(fg.0, fg.1, fg.2); ctx.set_line_width(underline_thickness); diff --git a/src/ui_model/line.rs b/src/ui_model/line.rs index 3f2b449..587895c 100644 --- a/src/ui_model/line.rs +++ b/src/ui_model/line.rs @@ -158,10 +158,6 @@ impl Line { 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> { let item_idx = self.cell_to_item(cell_idx); if item_idx >= 0 { diff --git a/src/ui_model/mod.rs b/src/ui_model/mod.rs index 006f3bc..26e20d2 100644 --- a/src/ui_model/mod.rs +++ b/src/ui_model/mod.rs @@ -74,13 +74,13 @@ impl UiModel { let mut changed_region = self.cur_point(); let line = &mut self.model[self.cur_row]; line.dirty_line = true; - line.mark_dirty_cell(self.cur_col); let cell = &mut line[self.cur_col]; cell.ch = text.chars().last().unwrap_or(' '); cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(Attrs::new); cell.attrs.double_width = text.is_empty(); + cell.dirty = true; self.cur_col += 1; if self.cur_col >= self.columns { self.cur_col -= 1;