From 9413af5a4e82ff32b82cd11135050e06e59f8b3e Mon Sep 17 00:00:00 2001 From: daa Date: Sat, 22 Apr 2017 12:08:03 +0300 Subject: [PATCH] Fix repaint underscore problem --- src/shell.rs | 19 +++++++++++++++---- src/ui_model.rs | 13 ++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/shell.rs b/src/shell.rs index c6e960e..edd94d5 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -441,16 +441,27 @@ fn draw_joined_rect(state: &State, ctx.move_to(current_point.0 + rect_width, current_point.1); } +#[inline] +fn get_model_clip(state: &State, line_height: f64, char_width: f64, clip: (f64, f64, f64, f64)) -> ModelRect { + let mut model_clip = + ModelRect::from_area(line_height, char_width, clip.0, clip.1, clip.2, clip.3); + // in some cases symbols from previous row affect next row + // for example underscore symbol or 'g' + // see deference between logical rect and ink rect + model_clip.extend(1, 0, 0, 0); + state.model.limit_to_model(&mut model_clip); + + model_clip +} + fn draw(state: &State, ctx: &cairo::Context) { ctx.set_source_rgb(state.bg_color.0, state.bg_color.1, state.bg_color.2); ctx.paint(); let line_height = state.line_height.unwrap(); let char_width = state.char_width.unwrap(); - let clip = ctx.clip_extents(); - let mut model_clip = - ModelRect::from_area(line_height, char_width, clip.0, clip.1, clip.2, clip.3); - state.model.limit_to_model(&mut model_clip); + + let model_clip = get_model_clip(state, line_height, char_width, ctx.clip_extents()); let line_x = model_clip.left as f64 * char_width; let mut line_y: f64 = model_clip.top as f64 * line_height; diff --git a/src/ui_model.rs b/src/ui_model.rs index 2e07ef5..c1faa09 100644 --- a/src/ui_model.rs +++ b/src/ui_model.rs @@ -230,7 +230,7 @@ impl UiModel { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ModelRect { pub top: usize, pub bot: usize, @@ -257,6 +257,17 @@ impl ModelRect { } } + pub fn extend(&mut self, top: usize, bot: usize, left: usize, right: usize) { + if self.top > 0 { + self.top -= top; + } + if self.left > 0 { + self.left -= left; + } + self.bot += bot; + self.right += right; + } + pub fn join(&mut self, rect: &ModelRect) { self.top = if self.top < rect.top { self.top