Render optimization + fix resize bug

This commit is contained in:
daa84 2017-03-30 18:25:54 +03:00
parent 62bcfb1f88
commit a04a035b84
3 changed files with 25 additions and 8 deletions

2
Cargo.lock generated
View File

@ -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)",

View File

@ -40,6 +40,7 @@ pub struct Shell {
sp_color: Color,
line_height: Option<f64>,
char_width: Option<f64>,
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)
}));

View File

@ -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
};