Merge branch 'master' into draw_rect
This commit is contained in:
commit
0f19874048
@ -1,4 +1,4 @@
|
|||||||
# neovim-gtk [![Build status](https://ci.appveyor.com/api/projects/status/l58o28e13f829llx?svg=true)](https://ci.appveyor.com/project/daa84/neovim-gtk)
|
# neovim-gtk [![Build status](https://ci.appveyor.com/api/projects/status/l58o28e13f829llx/branch/master?svg=true)](https://ci.appveyor.com/project/daa84/neovim-gtk/branch/master)
|
||||||
GTK ui for neovim written in rust using gtk-rs bindings.
|
GTK ui for neovim written in rust using gtk-rs bindings.
|
||||||
|
|
||||||
# Screenshot
|
# Screenshot
|
||||||
|
59
src/shell.rs
59
src/shell.rs
@ -441,29 +441,25 @@ fn draw_joined_rect(state: &State,
|
|||||||
ctx.move_to(current_point.0 + rect_width, current_point.1);
|
ctx.move_to(current_point.0 + rect_width, current_point.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(state: &State, ctx: &cairo::Context) {
|
#[inline]
|
||||||
ctx.set_source_rgb(state.bg_color.0, state.bg_color.1, state.bg_color.2);
|
fn get_model_clip(state: &State, line_height: f64, char_width: f64, clip: (f64, f64, f64, f64)) -> ModelRect {
|
||||||
ctx.paint();
|
|
||||||
|
|
||||||
let line_height = state.line_height.unwrap();
|
|
||||||
let char_width = state.char_width.unwrap();
|
|
||||||
let clip = ctx.clip_extents();
|
|
||||||
let mut model_clip =
|
let mut model_clip =
|
||||||
ModelRect::from_area(line_height, char_width, clip.0, clip.1, clip.2, clip.3);
|
ModelRect::from_area(line_height, char_width, clip.0, clip.1, clip.2, clip.3);
|
||||||
|
// in some cases symbols from previous row affect next row
|
||||||
|
// for example underscore symbol or 'g'
|
||||||
|
// see deference between logical rect and ink rect
|
||||||
|
model_clip.extend(1, 0, 0, 0);
|
||||||
state.model.limit_to_model(&mut model_clip);
|
state.model.limit_to_model(&mut model_clip);
|
||||||
|
|
||||||
|
model_clip
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn draw_backgound(state: &State, ctx: &cairo::Context, line_height: f64, char_width: f64, model_clip: &ModelRect) {
|
||||||
let line_x = model_clip.left as f64 * char_width;
|
let line_x = model_clip.left as f64 * char_width;
|
||||||
let mut line_y: f64 = model_clip.top as f64 * line_height;
|
let mut line_y: f64 = model_clip.top as f64 * line_height;
|
||||||
|
|
||||||
let (row, col) = state.model.get_cursor();
|
for (_, line) in state.model.clip_model(model_clip) {
|
||||||
let mut buf = String::with_capacity(4);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let layout = pc::create_layout(ctx);
|
|
||||||
let mut desc = state.create_pango_font();
|
|
||||||
|
|
||||||
for (line_idx, line) in state.model.clip_model(&model_clip) {
|
|
||||||
ctx.move_to(line_x, line_y);
|
ctx.move_to(line_x, line_y);
|
||||||
|
|
||||||
// first draw background
|
// first draw background
|
||||||
@ -497,6 +493,33 @@ fn draw(state: &State, ctx: &cairo::Context) {
|
|||||||
line_height,
|
line_height,
|
||||||
from_bg.take().unwrap());
|
from_bg.take().unwrap());
|
||||||
|
|
||||||
|
line_y += line_height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(state: &State, ctx: &cairo::Context) {
|
||||||
|
ctx.set_source_rgb(state.bg_color.0, state.bg_color.1, state.bg_color.2);
|
||||||
|
ctx.paint();
|
||||||
|
|
||||||
|
let line_height = state.line_height.unwrap();
|
||||||
|
let char_width = state.char_width.unwrap();
|
||||||
|
|
||||||
|
let model_clip = get_model_clip(state, line_height, char_width, ctx.clip_extents());
|
||||||
|
|
||||||
|
let line_x = model_clip.left as f64 * char_width;
|
||||||
|
let mut line_y: f64 = model_clip.top as f64 * line_height;
|
||||||
|
|
||||||
|
let (row, col) = state.model.get_cursor();
|
||||||
|
let mut buf = String::with_capacity(4);
|
||||||
|
|
||||||
|
|
||||||
|
let layout = pc::create_layout(ctx);
|
||||||
|
let mut desc = state.create_pango_font();
|
||||||
|
|
||||||
|
draw_backgound(state, ctx, line_height, char_width, &model_clip);
|
||||||
|
|
||||||
|
for (line_idx, line) in state.model.clip_model(&model_clip) {
|
||||||
|
|
||||||
ctx.move_to(line_x, line_y);
|
ctx.move_to(line_x, line_y);
|
||||||
|
|
||||||
for (col_idx, cell) in line.iter() {
|
for (col_idx, cell) in line.iter() {
|
||||||
@ -696,6 +719,10 @@ impl RedrawEvents for State {
|
|||||||
&RepaintMode::Area(ref rect) => {
|
&RepaintMode::Area(ref rect) => {
|
||||||
match (&self.line_height, &self.char_width) {
|
match (&self.line_height, &self.char_width) {
|
||||||
(&Some(line_height), &Some(char_width)) => {
|
(&Some(line_height), &Some(char_width)) => {
|
||||||
|
let mut rect = rect.clone();
|
||||||
|
// this need to repain also line under curren line
|
||||||
|
// in case underscore or 'g' symbol is go here
|
||||||
|
rect.extend(0, 1, 0, 0);
|
||||||
let (x, y, width, height) = rect.to_area(line_height, char_width);
|
let (x, y, width, height) = rect.to_area(line_height, char_width);
|
||||||
self.drawing_area.queue_draw_area(x, y, width, height);
|
self.drawing_area.queue_draw_area(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ impl ModelRectVec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub struct ModelRect {
|
pub struct ModelRect {
|
||||||
pub top: usize,
|
pub top: usize,
|
||||||
pub bot: usize,
|
pub bot: usize,
|
||||||
@ -302,6 +302,17 @@ impl ModelRect {
|
|||||||
other.bot >= self.top && other.bot <= self.bot
|
other.bot >= self.top && other.bot <= self.bot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn extend(&mut self, top: usize, bot: usize, left: usize, right: usize) {
|
||||||
|
if self.top > 0 {
|
||||||
|
self.top -= top;
|
||||||
|
}
|
||||||
|
if self.left > 0 {
|
||||||
|
self.left -= left;
|
||||||
|
}
|
||||||
|
self.bot += bot;
|
||||||
|
self.right += right;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn join(&mut self, rect: &ModelRect) {
|
pub fn join(&mut self, rect: &ModelRect) {
|
||||||
self.top = if self.top < rect.top {
|
self.top = if self.top < rect.top {
|
||||||
self.top
|
self.top
|
||||||
|
Loading…
Reference in New Issue
Block a user