Render optimization + fix resize bug
This commit is contained in:
parent
62bcfb1f88
commit
a04a035b84
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1,5 +1,5 @@
|
|||||||
[root]
|
[root]
|
||||||
name = "neovim-gtk"
|
name = "nvim-gtk"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cairo-rs 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cairo-rs 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
27
src/shell.rs
27
src/shell.rs
@ -40,6 +40,7 @@ pub struct Shell {
|
|||||||
sp_color: Color,
|
sp_color: Color,
|
||||||
line_height: Option<f64>,
|
line_height: Option<f64>,
|
||||||
char_width: Option<f64>,
|
char_width: Option<f64>,
|
||||||
|
request_width: bool,
|
||||||
pub mode: NvimMode,
|
pub mode: NvimMode,
|
||||||
mouse_enabled: bool,
|
mouse_enabled: bool,
|
||||||
mouse_pressed: bool,
|
mouse_pressed: bool,
|
||||||
@ -60,6 +61,7 @@ impl Shell {
|
|||||||
sp_color: COLOR_RED,
|
sp_color: COLOR_RED,
|
||||||
line_height: None,
|
line_height: None,
|
||||||
char_width: None,
|
char_width: None,
|
||||||
|
request_width: true,
|
||||||
mode: NvimMode::Normal,
|
mode: NvimMode::Normal,
|
||||||
mouse_enabled: true,
|
mouse_enabled: true,
|
||||||
mouse_pressed: false,
|
mouse_pressed: false,
|
||||||
@ -106,8 +108,14 @@ impl Shell {
|
|||||||
self.font_desc.clone()
|
self.font_desc.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn request_width(&mut self) {
|
||||||
|
self.request_width = true;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_font_desc(&mut self, desc: &str) {
|
pub fn set_font_desc(&mut self, desc: &str) {
|
||||||
self.font_desc = FontDescription::from_string(desc);
|
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) {
|
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| {
|
UI.with(|ui_cell| {
|
||||||
let mut ui = ui_cell.borrow_mut();
|
let mut ui = ui_cell.borrow_mut();
|
||||||
|
|
||||||
let (width, height) = calc_char_bounds(&ui.shell, ctx);
|
if ui.shell.line_height.is_none() {
|
||||||
ui.shell.line_height = Some(height as f64);
|
let (width, height) = calc_char_bounds(&ui.shell, ctx);
|
||||||
ui.shell.char_width = Some(width as f64);
|
ui.shell.line_height = Some(height as f64);
|
||||||
|
ui.shell.char_width = Some(width as f64);
|
||||||
|
}
|
||||||
|
|
||||||
draw(&ui.shell, ctx);
|
draw(&ui.shell, ctx);
|
||||||
request_width(&ui);
|
|
||||||
|
request_width(&mut ui);
|
||||||
});
|
});
|
||||||
|
|
||||||
Inhibit(false)
|
Inhibit(false)
|
||||||
@ -411,11 +422,16 @@ fn calc_char_bounds(shell: &Shell, ctx: &cairo::Context) -> (i32, i32) {
|
|||||||
layout.get_pixel_size()
|
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() {
|
if ui.shell.resize_timer.is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.shell.request_width = false;
|
||||||
|
|
||||||
let width = ui.shell.drawing_area.get_allocated_width();
|
let width = ui.shell.drawing_area.get_allocated_width();
|
||||||
let height = ui.shell.drawing_area.get_allocated_height();
|
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;
|
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);
|
println!("Error trying resize nvim {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
shell.request_width();
|
||||||
});
|
});
|
||||||
Continue(false)
|
Continue(false)
|
||||||
}));
|
}));
|
||||||
|
@ -310,7 +310,7 @@ impl ModelRect {
|
|||||||
y2: f64)
|
y2: f64)
|
||||||
-> ModelRect {
|
-> ModelRect {
|
||||||
let x1 = if x1 > 0.0 {
|
let x1 = if x1 > 0.0 {
|
||||||
x1 - 1.0
|
x1 // - 1.0
|
||||||
} else {
|
} else {
|
||||||
x1
|
x1
|
||||||
};
|
};
|
||||||
@ -320,7 +320,7 @@ impl ModelRect {
|
|||||||
x2
|
x2
|
||||||
};
|
};
|
||||||
let y1 = if y1 > 0.0 {
|
let y1 = if y1 > 0.0 {
|
||||||
y1 - 1.0
|
y1 // - 1.0
|
||||||
} else {
|
} else {
|
||||||
y1
|
y1
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user