Fix rendering
This commit is contained in:
parent
3bb326c8aa
commit
c4ecd43ea0
@ -22,7 +22,11 @@ impl Context {
|
||||
}
|
||||
|
||||
pub fn itemize(&self, line: &StyledLine) -> Vec<sys_pango::Item> {
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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<pango::GlyphString>,
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user