From eea93fb284929ef0c86d773d393e3f8893ffbedd Mon Sep 17 00:00:00 2001 From: daa84 Date: Fri, 21 Apr 2017 21:52:54 +0300 Subject: [PATCH 1/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98f3c63..eb44fc9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# neovim-gtk [![Build status](https://ci.appveyor.com/api/projects/status/l58o28e13f829llx?svg=true)](https://ci.appveyor.com/project/daa84/neovim-gtk) +# neovim-gtk [![Build status](https://ci.appveyor.com/api/projects/status/l58o28e13f829llx/branch/master?svg=true)](https://ci.appveyor.com/project/daa84/neovim-gtk/branch/master) GTK ui for neovim written in rust using gtk-rs bindings. # Screenshot From 9413af5a4e82ff32b82cd11135050e06e59f8b3e Mon Sep 17 00:00:00 2001 From: daa Date: Sat, 22 Apr 2017 12:08:03 +0300 Subject: [PATCH 2/3] 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 From 751c4eb6fad54e3f8141d8ef4249b07597854c54 Mon Sep 17 00:00:00 2001 From: daa Date: Sat, 22 Apr 2017 12:33:36 +0300 Subject: [PATCH 3/3] Fix repaint of underscore --- src/shell.rs | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/shell.rs b/src/shell.rs index edd94d5..babd243 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -454,27 +454,12 @@ fn get_model_clip(state: &State, line_height: f64, char_width: f64, clip: (f64, 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 model_clip = get_model_clip(state, line_height, char_width, ctx.clip_extents()); - +#[inline] +fn draw_backgound(state: &State, ctx: &cairo::Context, line_height: f64, char_width: f64, model_clip: &ModelRect) { let line_x = model_clip.left as f64 * char_width; let mut line_y: f64 = model_clip.top as f64 * line_height; - let (row, col) = state.model.get_cursor(); - let mut buf = String::with_capacity(4); - - - - let layout = pc::create_layout(ctx); - let mut desc = state.create_pango_font(); - - for (line_idx, line) in state.model.clip_model(&model_clip) { + for (_, line) in state.model.clip_model(model_clip) { ctx.move_to(line_x, line_y); // first draw background @@ -508,6 +493,33 @@ fn draw(state: &State, ctx: &cairo::Context) { line_height, from_bg.take().unwrap()); + line_y += line_height; + } +} + +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 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; + + let (row, col) = state.model.get_cursor(); + let mut buf = String::with_capacity(4); + + + let layout = pc::create_layout(ctx); + let mut desc = state.create_pango_font(); + + draw_backgound(state, ctx, line_height, char_width, &model_clip); + + for (line_idx, line) in state.model.clip_model(&model_clip) { + ctx.move_to(line_x, line_y); for (col_idx, cell) in line.iter() { @@ -707,6 +719,10 @@ impl RedrawEvents for State { &RepaintMode::Area(ref rect) => { match (&self.line_height, &self.char_width) { (&Some(line_height), &Some(char_width)) => { + let mut rect = rect.clone(); + // this need to repain also line under curren line + // in case underscore or 'g' symbol is go here + rect.extend(0, 1, 0, 0); let (x, y, width, height) = rect.to_area(line_height, char_width); self.drawing_area.queue_draw_area(x, y, width, height); }