neovim-gtk/src/render/mod.rs

81 lines
2.2 KiB
Rust
Raw Normal View History

2017-08-24 14:41:20 +00:00
mod context;
2017-08-31 15:37:55 +00:00
pub use self::context::Context;
use color;
use sys::pango::*;
use pango;
use cairo;
2017-08-26 20:17:09 +00:00
use pangocairo::CairoContextExt;
2017-08-24 14:41:20 +00:00
use ui_model;
2017-08-25 15:32:30 +00:00
pub fn render(
ctx: &cairo::Context,
2017-08-31 15:37:55 +00:00
ui_model: &ui_model::UiModel,
color_model: &color::ColorModel,
2017-08-26 20:17:09 +00:00
line_height: f64,
char_width: f64,
2017-08-25 15:32:30 +00:00
) {
2017-08-31 15:37:55 +00:00
ctx.set_source_rgb(
color_model.bg_color.0,
color_model.bg_color.1,
color_model.bg_color.2,
);
ctx.paint();
2017-08-25 15:32:30 +00:00
2017-08-26 20:17:09 +00:00
let mut line_y = line_height;
2017-08-31 15:37:55 +00:00
for line in ui_model.model() {
2017-08-27 19:29:43 +00:00
let mut line_x = 0.0;
2017-08-31 15:37:55 +00:00
2017-08-25 15:32:30 +00:00
for i in 0..line.line.len() {
2017-08-27 19:29:43 +00:00
ctx.move_to(line_x, line_y);
2017-08-31 15:37:55 +00:00
if let Some(item) = line.item_line[i].as_ref() {
2017-08-25 15:32:30 +00:00
if let Some(ref glyphs) = item.glyphs {
2017-08-31 15:37:55 +00:00
let (_, fg) = color_model.cell_colors(&line.line[i]);
ctx.set_source_rgb(fg.0, fg.1, fg.2);
2017-08-26 20:17:09 +00:00
ctx.show_glyph_string(item.font(), glyphs);
2017-08-25 15:32:30 +00:00
}
}
2017-08-27 19:29:43 +00:00
line_x += char_width;
2017-08-25 15:32:30 +00:00
}
2017-08-26 20:17:09 +00:00
line_y += line_height;
2017-08-25 15:32:30 +00:00
}
}
2017-08-31 15:37:55 +00:00
pub fn shape_dirty(ctx: &context::Context, ui_model: &mut ui_model::UiModel) {
2017-08-25 15:32:30 +00:00
for line in ui_model.model_mut() {
if line.dirty_line {
let styled_line = ui_model::StyledLine::from(line);
let items = ctx.itemize(&styled_line);
line.merge(&styled_line, &items);
for i in 0..line.line.len() {
if line[i].dirty {
2017-08-27 19:29:43 +00:00
if let Some(mut item) = line.get_item_mut(i) {
let mut glyphs = pango::GlyphString::new();
{
let analysis = item.analysis();
let (offset, length, _) = item.item.offset();
pango_shape(
&styled_line.line_str,
offset,
length,
&analysis,
&mut glyphs,
);
}
2017-08-25 15:32:30 +00:00
2017-08-27 19:29:43 +00:00
item.set_glyphs(glyphs);
}
2017-08-25 15:32:30 +00:00
}
line[i].dirty = false;
}
line.dirty_line = false;
}
2017-08-23 09:45:56 +00:00
}
}
2017-08-24 14:41:20 +00:00