From 0c64c43278a1f33f97fc4f00d90ce8ee9539b9e3 Mon Sep 17 00:00:00 2001 From: daa Date: Sun, 3 Apr 2016 16:04:52 +0300 Subject: [PATCH] Fix colors, some update of buttons bindings, eol_clear implementation, quit button --- build.rs | 2 ++ src/nvim.rs | 8 ++++++++ src/ui.rs | 7 ++++++- src/ui_model.rs | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 238efaa..9cb4bd6 100644 --- a/build.rs +++ b/build.rs @@ -38,6 +38,7 @@ fn main() { .entry("less", "\"<\"") .entry("greater", "\">\"") .entry("comma", "\",\"") + .entry("colon", "\":\"") .entry("period", "\".\"") .entry("BackSpace", "\"BS\"") .entry("space", "\"space\"") @@ -47,6 +48,7 @@ fn main() { .entry("Page_Up", "\"PageUp\"") .entry("Page_Down", "\"PageDown\"") .entry("Enter", "\"CR\"") + .entry("Tab", "\"Tab\"") .entry("ISO_Left_Tab", "\"Tab\"") .build(&mut file) .unwrap(); diff --git a/src/nvim.rs b/src/nvim.rs index ebe5e98..2f6b70d 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -21,6 +21,8 @@ pub trait RedrawEvents { fn on_redraw(&self); fn on_highlight_set(&mut self, attrs: &HashMap); + + fn on_eol_clear(&mut self); } macro_rules! try_str { @@ -129,6 +131,12 @@ fn call(method: &str, args: Vec) { Ok(()) }); } + "eol_clear" => { + safe_call(move |ui| { + ui.on_eol_clear(); + Ok(()) + }) + } _ => println!("Event {}({:?})", method, args), }; } diff --git a/src/ui.rs b/src/ui.rs index 1d9a76a..a75815d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -77,6 +77,7 @@ impl Ui { let exit_image = Image::new_from_icon_name("application-exit", 50); let exit_btn = ToolButton::new(Some(&exit_image), None); + exit_btn.connect_clicked(|_| gtk::main_quit()); button_bar.add(&exit_btn); grid.attach(&button_bar, 0, 0, 1, 1); @@ -231,6 +232,10 @@ impl RedrawEvents for Ui { self.model.clear(); } + fn on_eol_clear(&mut self) { + self.model.eol_clear(); + } + fn on_resize(&mut self, columns: u64, rows: u64) { self.model = UiModel::new(rows, columns); } @@ -260,5 +265,5 @@ fn split_color(indexed_color: u64) -> Color { let r = ((indexed_color >> 16) & 0xff) as f64; let g = ((indexed_color >> 8) & 0xff) as f64; let b = (indexed_color & 0xff) as f64; - Color(255.0 / r, 255.0 / g, 255.0 / b) + Color(r / 255.0, g / 255.0, b / 255.0) } diff --git a/src/ui_model.rs b/src/ui_model.rs index ed93ad8..4ddb03a 100644 --- a/src/ui_model.rs +++ b/src/ui_model.rs @@ -22,6 +22,13 @@ impl Attrs { bold: false, } } + + fn clear(&mut self) { + self.italic = false; + self.bold = false; + self.foreground = COLOR_WHITE; + self.background = COLOR_BLACK; + } } pub struct Cell { @@ -39,6 +46,7 @@ impl Cell { fn clear(&mut self) { self.ch = ' '; + self.attrs.clear(); } } @@ -96,4 +104,17 @@ impl UiModel { } } } + + pub fn eol_clear(&mut self) { + let (cur_row, cur_col, columns) = (self.cur_row, self.cur_col, self.columns); + self.clear_region(cur_row, cur_row, cur_col, columns - 1); + } + + fn clear_region(&mut self, top: usize, bot: usize, left: usize, right: usize) { + for row in top..bot + 1 { + for col in left..right + 1 { + self.model[row][col].clear(); + } + } + } }