From c4ecd43ea001077f0cf7cf38f5a8d754f6f592a0 Mon Sep 17 00:00:00 2001 From: daa84 Date: Mon, 4 Sep 2017 18:32:12 +0300 Subject: [PATCH] Fix rendering --- src/render/context.rs | 6 +++++- src/render/mod.rs | 9 ++++++--- src/shell.rs | 2 +- src/ui_model/line.rs | 19 ++++++++++++++----- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/render/context.rs b/src/render/context.rs index ff356a1..9b1fde6 100644 --- a/src/render/context.rs +++ b/src/render/context.rs @@ -22,7 +22,11 @@ impl Context { } pub fn itemize(&self, line: &StyledLine) -> Vec { - sys_pango::pango_itemize(&self.pango_context, line.line_str.trim_right(), &line.attr_list) + sys_pango::pango_itemize( + &self.pango_context, + line.line_str.trim_right(), + &line.attr_list, + ) } } diff --git a/src/render/mod.rs b/src/render/mod.rs index 6bb88ce..15a9c72 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -43,10 +43,14 @@ pub fn render( } } -pub fn shape_dirty(ctx: &context::Context, ui_model: &mut ui_model::UiModel) { +pub fn shape_dirty( + ctx: &context::Context, + ui_model: &mut ui_model::UiModel, + color_model: &color::ColorModel, +) { for line in ui_model.model_mut() { if line.dirty_line { - let styled_line = ui_model::StyledLine::from(line); + let styled_line = ui_model::StyledLine::from(line, color_model); let items = ctx.itemize(&styled_line); line.merge(&styled_line, &items); @@ -77,4 +81,3 @@ pub fn shape_dirty(ctx: &context::Context, ui_model: &mut ui_model::UiModel) { } } } - diff --git a/src/shell.rs b/src/shell.rs index 5f09e3f..f6685f8 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -625,7 +625,7 @@ fn render(state: &mut State, ctx: &cairo::Context) { let font_ctx = render::Context::new(&font_desc); - render::shape_dirty(&font_ctx, &mut state.model); + render::shape_dirty(&font_ctx, &mut state.model, &state.color_model); render::render( ctx, &state.model, diff --git a/src/ui_model/line.rs b/src/ui_model/line.rs index d419dff..cff25bb 100644 --- a/src/ui_model/line.rs +++ b/src/ui_model/line.rs @@ -1,9 +1,11 @@ use std::ops::{Index, IndexMut}; +use color; use super::cell::Cell; use sys::pango as sys_pango; use pango; +#[derive(Clone)] pub struct Item { pub item: sys_pango::Item, pub glyphs: Option, @@ -77,9 +79,9 @@ impl Line { pub fn copy_to(&self, target: &mut Self, left: usize, right: usize) { target.line[left..right + 1].clone_from_slice(&self.line[left..right + 1]); - // don't update items, but mark line as dirty to force item recalculation - // all work must be done in merge function - target.dirty_line = true; + target.item_line[left..right + 1].clone_from_slice(&self.item_line[left..right + 1]); + target.cell_to_item[left..right + 1].copy_from_slice(&self.cell_to_item[left..right + 1]); + target.dirty_line = self.dirty_line; } pub fn clear(&mut self, left: usize, right: usize) { @@ -260,7 +262,7 @@ pub struct StyledLine { } impl StyledLine { - pub fn from(line: &Line) -> Self { + pub fn from(line: &Line, color_model: &color::ColorModel) -> Self { let mut line_str = String::new(); let mut cell_to_byte = Vec::new(); let attr_list = pango::AttrList::new(); @@ -281,6 +283,7 @@ impl StyledLine { if !cell.ch.is_whitespace() { insert_attrs( cell, + color_model, &attr_list, byte_offset as u32, (byte_offset + len) as u32, @@ -298,7 +301,13 @@ impl StyledLine { } } -fn insert_attrs(cell: &Cell, attr_list: &pango::AttrList, start_idx: u32, end_idx: u32) { +fn insert_attrs( + cell: &Cell, + color_model: &color::ColorModel, + attr_list: &pango::AttrList, + start_idx: u32, + end_idx: u32, +) { if cell.attrs.italic { let mut attr = pango::Attribute::new_style(pango::Style::Italic).unwrap(); attr.set_start_index(start_idx);