Implement busy_start/stop cursor hiding

This commit is contained in:
daa84 2017-04-03 18:16:04 +03:00
parent 1a2e2a4d9b
commit 057fad0e87
3 changed files with 31 additions and 10 deletions

View File

@ -37,6 +37,7 @@ enum AnimPhase {
Hidden,
Show,
NoFocus,
Busy,
}
struct State {
@ -93,6 +94,14 @@ impl Cursor {
self.state.borrow_mut().reset_to(AnimPhase::NoFocus);
}
pub fn busy_on(&mut self) {
self.state.borrow_mut().reset_to(AnimPhase::Busy);
}
pub fn busy_off(&mut self) {
self.start();
}
pub fn draw(&self,
ctx: &cairo::Context,
shell: &Shell,
@ -102,8 +111,13 @@ impl Cursor {
double_width: bool,
bg: &Color) {
let current_point = ctx.get_current_point();
let state = self.state.borrow();
if state.anim_phase == AnimPhase::Busy {
return;
}
let current_point = ctx.get_current_point();
ctx.set_source_rgba(1.0 - bg.0, 1.0 - bg.1, 1.0 - bg.2, 0.6 * state.alpha.0);
let cursor_width = if shell.mode == NvimMode::Insert {
@ -158,6 +172,7 @@ fn anim_step(state: &Arc<UiMutex<State>>) -> glib::Continue {
}
}
AnimPhase::NoFocus => None,
AnimPhase::Busy => None,
};
SHELL!(&shell = {

View File

@ -33,9 +33,9 @@ pub trait RedrawEvents {
fn on_mode_change(&mut self, mode: &str) -> RepaintMode;
fn on_mouse_on(&mut self) -> RepaintMode;
fn on_mouse(&mut self, on: bool) -> RepaintMode;
fn on_mouse_off(&mut self) -> RepaintMode;
fn on_busy(&mut self, busy: bool) -> RepaintMode;
}
pub trait GuiApi {
@ -189,8 +189,10 @@ fn call(ui: &mut Shell, method: &str, args: &Vec<Value>) -> result::Result<Repai
"update_fg" => ui.on_update_fg(try_int!(args[0])),
"update_sp" => ui.on_update_sp(try_int!(args[0])),
"mode_change" => ui.on_mode_change(try_str!(args[0])),
"mouse_on" => ui.on_mouse_on(),
"mouse_off" => ui.on_mouse_off(),
"mouse_on" => ui.on_mouse(true),
"mouse_off" => ui.on_mouse(false),
"busy_start" => ui.on_busy(true),
"busy_stop" => ui.on_busy(false),
_ => {
println!("Event {}({:?})", method, args);
RepaintMode::Nothing

View File

@ -636,14 +636,18 @@ impl RedrawEvents for Shell {
RepaintMode::Area(self.model.cur_point())
}
fn on_mouse_on(&mut self) -> RepaintMode {
self.mouse_enabled = true;
fn on_mouse(&mut self, on: bool) -> RepaintMode {
self.mouse_enabled = on;
RepaintMode::Nothing
}
fn on_mouse_off(&mut self) -> RepaintMode {
self.mouse_enabled = false;
RepaintMode::Nothing
fn on_busy(&mut self, busy: bool) -> RepaintMode {
if busy {
self.cursor.busy_on();
} else {
self.cursor.busy_off();
}
RepaintMode::Area(self.model.cur_point())
}
}