From a04a035b8433f26baff50b81bb39f61424514075 Mon Sep 17 00:00:00 2001 From: daa84 Date: Thu, 30 Mar 2017 18:25:54 +0300 Subject: [PATCH] Render optimization + fix resize bug --- Cargo.lock | 2 +- src/shell.rs | 27 ++++++++++++++++++++++----- src/ui_model.rs | 4 ++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33fd59b..d8f83a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,5 @@ [root] -name = "neovim-gtk" +name = "nvim-gtk" version = "0.1.1" dependencies = [ "cairo-rs 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/shell.rs b/src/shell.rs index 1844462..da170a6 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -40,6 +40,7 @@ pub struct Shell { sp_color: Color, line_height: Option, char_width: Option, + request_width: bool, pub mode: NvimMode, mouse_enabled: bool, mouse_pressed: bool, @@ -60,6 +61,7 @@ impl Shell { sp_color: COLOR_RED, line_height: None, char_width: None, + request_width: true, mode: NvimMode::Normal, mouse_enabled: true, mouse_pressed: false, @@ -106,8 +108,14 @@ impl Shell { self.font_desc.clone() } + fn request_width(&mut self) { + self.request_width = true; + } + pub fn set_font_desc(&mut self, desc: &str) { self.font_desc = FontDescription::from_string(desc); + self.line_height = None; + self.char_width = None; } pub fn colors<'a>(&'a self, cell: &'a Cell) -> (&'a Color, &'a Color) { @@ -231,12 +239,15 @@ fn gtk_draw(_: &DrawingArea, ctx: &cairo::Context) -> Inhibit { UI.with(|ui_cell| { let mut ui = ui_cell.borrow_mut(); - let (width, height) = calc_char_bounds(&ui.shell, ctx); - ui.shell.line_height = Some(height as f64); - ui.shell.char_width = Some(width as f64); + if ui.shell.line_height.is_none() { + let (width, height) = calc_char_bounds(&ui.shell, ctx); + ui.shell.line_height = Some(height as f64); + ui.shell.char_width = Some(width as f64); + } draw(&ui.shell, ctx); - request_width(&ui); + + request_width(&mut ui); }); Inhibit(false) @@ -411,11 +422,16 @@ fn calc_char_bounds(shell: &Shell, ctx: &cairo::Context) -> (i32, i32) { layout.get_pixel_size() } -fn request_width(ui: &Ui) { +fn request_width(ui: &mut Ui) { + if !ui.shell.request_width { + return; + } if ui.shell.resize_timer.is_some() { return; } + ui.shell.request_width = false; + let width = ui.shell.drawing_area.get_allocated_width(); let height = ui.shell.drawing_area.get_allocated_height(); let request_height = (ui.shell.model.rows as f64 * ui.shell.line_height.unwrap()) as i32; @@ -459,6 +475,7 @@ fn gtk_configure_event(_: &DrawingArea, ev: &EventConfigure) -> bool { println!("Error trying resize nvim {}", err); } } + shell.request_width(); }); Continue(false) })); diff --git a/src/ui_model.rs b/src/ui_model.rs index 5d17f58..d045319 100644 --- a/src/ui_model.rs +++ b/src/ui_model.rs @@ -310,7 +310,7 @@ impl ModelRect { y2: f64) -> ModelRect { let x1 = if x1 > 0.0 { - x1 - 1.0 + x1 // - 1.0 } else { x1 }; @@ -320,7 +320,7 @@ impl ModelRect { x2 }; let y1 = if y1 > 0.0 { - y1 - 1.0 + y1 // - 1.0 } else { y1 };