Repaint event on given area

This commit is contained in:
daa 2017-03-18 01:18:41 +03:00
parent a92b42f784
commit 51dcd7f4e8
4 changed files with 42 additions and 9 deletions

View File

@ -1,7 +1,7 @@
use neovim_lib::{Neovim, NeovimApi, Session, Value, Integer, UiAttachOptions, CallError};
use std::io::{Result, Error, ErrorKind};
use std::result;
use ui_model::UiModel;
use ui_model::{UiModel, ModelRect};
use ui;
use shell::Shell;
use glib;
@ -15,7 +15,7 @@ pub trait RedrawEvents {
fn on_resize(&mut self, columns: u64, rows: u64);
fn on_redraw(&self);
fn on_redraw(&self, mode: &RepaintMode);
fn on_highlight_set(&mut self, attrs: &Vec<(Value, Value)>);
@ -114,7 +114,7 @@ fn nvim_cb(method: &str, params: Vec<Value>) {
}
}
ui.on_redraw();
ui.on_redraw(&RepaintMode::All);
Ok(())
});
}
@ -124,7 +124,7 @@ fn nvim_cb(method: &str, params: Vec<Value>) {
let args = params.iter().skip(1).cloned().collect();
safe_call(move |ui| {
call_gui_event(ui, &ev_name, &args)?;
ui.on_redraw();
ui.on_redraw(&RepaintMode::All);
Ok(())
});
} else {
@ -204,3 +204,9 @@ impl<T> ErrorReport for result::Result<T, CallError> {
}
}
}
pub enum RepaintMode {
All,
Area(ModelRect),
}

View File

@ -1,6 +1,9 @@
#[cfg(unix)]
use ui::{UI, SET};
#[cfg(unix)]
use nvim::RepaintMode;
#[cfg(unix)]
use nvim::RedrawEvents;
@ -77,7 +80,7 @@ fn monospace_font_changed() {
// rpc is priority for font
if set.font_source != FontSource::Rpc {
set.update_font(&mut ui.shell);
ui.shell.on_redraw();
ui.shell.on_redraw(&RepaintMode::All);
}
});
});

View File

@ -14,19 +14,25 @@ use neovim_lib::{Neovim, NeovimApi, Value, Integer};
use settings;
use ui_model::{UiModel, Cell, Attrs, Color, COLOR_BLACK, COLOR_WHITE, COLOR_RED};
use nvim::{RedrawEvents, GuiApi};
use nvim::{RedrawEvents, GuiApi, RepaintMode};
use input::{convert_key, keyval_to_input_string};
use ui::{UI, Ui, SET};
const DEFAULT_FONT_NAME: &'static str = "DejaVu Sans Mono 12";
macro_rules! SHELL {
(&$id:ident = $expr:expr) => (
UI.with(|ui_cell| {
let $id = &ui_cell.borrow().shell;
$expr
});
);
($id:ident = $expr:expr) => (
UI.with(|ui_cell| {
let mut $id = &mut ui_cell.borrow_mut().shell;
$expr
});
)
);
}
#[derive(PartialEq)]
@ -473,8 +479,20 @@ impl RedrawEvents for Shell {
self.model = UiModel::new(rows, columns);
}
fn on_redraw(&self) {
self.drawing_area.queue_draw();
fn on_redraw(&self, mode: &RepaintMode) {
match mode {
&RepaintMode::All => self.drawing_area.queue_draw(),
&RepaintMode::Area(ref rect) => {
SHELL!(&shell = {
if let Some(line_height) = shell.line_height {
if let Some(char_width) = shell.char_width {
let (x, y, width, height) = rect.to_area(line_height as i32, char_width as i32);
self.drawing_area.queue_draw_area(x, y, width, height);
}
}
});
},
}
}
fn on_set_scroll_region(&mut self, top: u64, bot: u64, left: u64, right: u64) {

View File

@ -258,4 +258,10 @@ impl ModelRect {
rect.right
};
}
pub fn to_area(&self, line_height: i32, char_width: i32) -> (i32, i32, i32, i32) {
let y = self.top as i32 * line_height;
let x = self.left as i32 * char_width;
(x, y, self.right as i32 * char_width - x, self.bot as i32 * line_height - y)
}
}