From c458f90740d0d4823c188917e445ac76bc1721af Mon Sep 17 00:00:00 2001 From: daa84 Date: Wed, 22 Mar 2017 13:05:10 +0300 Subject: [PATCH] Exctract cursor code --- src/cursor.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/cursor.rs diff --git a/src/cursor.rs b/src/cursor.rs new file mode 100644 index 0000000..1dbbcc9 --- /dev/null +++ b/src/cursor.rs @@ -0,0 +1,31 @@ +use cairo; +use ui_model::Color; +use shell::{Shell, NvimMode}; + +pub struct Cursor { +} + +impl Cursor { + pub fn new() -> Cursor { + Cursor { } + } + + pub fn draw(&self, ctx: &cairo::Context, shell: &Shell, + char_width: f64, line_height: f64, line_y: f64, double_width: bool, bg: &Color) { + let current_point = ctx.get_current_point(); + ctx.set_source_rgba(1.0 - bg.0, 1.0 - bg.1, 1.0 - bg.2, 0.5); + + let cursor_width = if shell.mode == NvimMode::Insert { + char_width / 5.0 + } else { + if double_width { + char_width * 2.0 + } else { + char_width + } + }; + + ctx.rectangle(current_point.0, line_y, cursor_width, line_height); + ctx.fill(); + } +}