Repaint event on given area
This commit is contained in:
parent
a92b42f784
commit
51dcd7f4e8
14
src/nvim.rs
14
src/nvim.rs
@ -1,7 +1,7 @@
|
|||||||
use neovim_lib::{Neovim, NeovimApi, Session, Value, Integer, UiAttachOptions, CallError};
|
use neovim_lib::{Neovim, NeovimApi, Session, Value, Integer, UiAttachOptions, CallError};
|
||||||
use std::io::{Result, Error, ErrorKind};
|
use std::io::{Result, Error, ErrorKind};
|
||||||
use std::result;
|
use std::result;
|
||||||
use ui_model::UiModel;
|
use ui_model::{UiModel, ModelRect};
|
||||||
use ui;
|
use ui;
|
||||||
use shell::Shell;
|
use shell::Shell;
|
||||||
use glib;
|
use glib;
|
||||||
@ -15,7 +15,7 @@ pub trait RedrawEvents {
|
|||||||
|
|
||||||
fn on_resize(&mut self, columns: u64, rows: u64);
|
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)>);
|
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(())
|
Ok(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ fn nvim_cb(method: &str, params: Vec<Value>) {
|
|||||||
let args = params.iter().skip(1).cloned().collect();
|
let args = params.iter().skip(1).cloned().collect();
|
||||||
safe_call(move |ui| {
|
safe_call(move |ui| {
|
||||||
call_gui_event(ui, &ev_name, &args)?;
|
call_gui_event(ui, &ev_name, &args)?;
|
||||||
ui.on_redraw();
|
ui.on_redraw(&RepaintMode::All);
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -204,3 +204,9 @@ impl<T> ErrorReport for result::Result<T, CallError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum RepaintMode {
|
||||||
|
All,
|
||||||
|
Area(ModelRect),
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use ui::{UI, SET};
|
use ui::{UI, SET};
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use nvim::RepaintMode;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use nvim::RedrawEvents;
|
use nvim::RedrawEvents;
|
||||||
|
|
||||||
@ -77,7 +80,7 @@ fn monospace_font_changed() {
|
|||||||
// rpc is priority for font
|
// rpc is priority for font
|
||||||
if set.font_source != FontSource::Rpc {
|
if set.font_source != FontSource::Rpc {
|
||||||
set.update_font(&mut ui.shell);
|
set.update_font(&mut ui.shell);
|
||||||
ui.shell.on_redraw();
|
ui.shell.on_redraw(&RepaintMode::All);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
26
src/shell.rs
26
src/shell.rs
@ -14,19 +14,25 @@ use neovim_lib::{Neovim, NeovimApi, Value, Integer};
|
|||||||
|
|
||||||
use settings;
|
use settings;
|
||||||
use ui_model::{UiModel, Cell, Attrs, Color, COLOR_BLACK, COLOR_WHITE, COLOR_RED};
|
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 input::{convert_key, keyval_to_input_string};
|
||||||
use ui::{UI, Ui, SET};
|
use ui::{UI, Ui, SET};
|
||||||
|
|
||||||
const DEFAULT_FONT_NAME: &'static str = "DejaVu Sans Mono 12";
|
const DEFAULT_FONT_NAME: &'static str = "DejaVu Sans Mono 12";
|
||||||
|
|
||||||
macro_rules! SHELL {
|
macro_rules! SHELL {
|
||||||
|
(&$id:ident = $expr:expr) => (
|
||||||
|
UI.with(|ui_cell| {
|
||||||
|
let $id = &ui_cell.borrow().shell;
|
||||||
|
$expr
|
||||||
|
});
|
||||||
|
);
|
||||||
($id:ident = $expr:expr) => (
|
($id:ident = $expr:expr) => (
|
||||||
UI.with(|ui_cell| {
|
UI.with(|ui_cell| {
|
||||||
let mut $id = &mut ui_cell.borrow_mut().shell;
|
let mut $id = &mut ui_cell.borrow_mut().shell;
|
||||||
$expr
|
$expr
|
||||||
});
|
});
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
@ -473,8 +479,20 @@ impl RedrawEvents for Shell {
|
|||||||
self.model = UiModel::new(rows, columns);
|
self.model = UiModel::new(rows, columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_redraw(&self) {
|
fn on_redraw(&self, mode: &RepaintMode) {
|
||||||
self.drawing_area.queue_draw();
|
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) {
|
fn on_set_scroll_region(&mut self, top: u64, bot: u64, left: u64, right: u64) {
|
||||||
|
@ -258,4 +258,10 @@ impl ModelRect {
|
|||||||
rect.right
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user