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> {
|
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() {
|
for line in ui_model.model_mut() {
|
||||||
if line.dirty_line {
|
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);
|
let items = ctx.itemize(&styled_line);
|
||||||
line.merge(&styled_line, &items);
|
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);
|
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(
|
render::render(
|
||||||
ctx,
|
ctx,
|
||||||
&state.model,
|
&state.model,
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
|
|
||||||
|
use color;
|
||||||
use super::cell::Cell;
|
use super::cell::Cell;
|
||||||
use sys::pango as sys_pango;
|
use sys::pango as sys_pango;
|
||||||
use pango;
|
use pango;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub item: sys_pango::Item,
|
pub item: sys_pango::Item,
|
||||||
pub glyphs: Option<pango::GlyphString>,
|
pub glyphs: Option<pango::GlyphString>,
|
||||||
@ -77,9 +79,9 @@ impl Line {
|
|||||||
|
|
||||||
pub fn copy_to(&self, target: &mut Self, left: usize, right: usize) {
|
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]);
|
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
|
target.item_line[left..right + 1].clone_from_slice(&self.item_line[left..right + 1]);
|
||||||
// all work must be done in merge function
|
target.cell_to_item[left..right + 1].copy_from_slice(&self.cell_to_item[left..right + 1]);
|
||||||
target.dirty_line = true;
|
target.dirty_line = self.dirty_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&mut self, left: usize, right: usize) {
|
pub fn clear(&mut self, left: usize, right: usize) {
|
||||||
@ -260,7 +262,7 @@ pub struct StyledLine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 line_str = String::new();
|
||||||
let mut cell_to_byte = Vec::new();
|
let mut cell_to_byte = Vec::new();
|
||||||
let attr_list = pango::AttrList::new();
|
let attr_list = pango::AttrList::new();
|
||||||
@ -281,6 +283,7 @@ impl StyledLine {
|
|||||||
if !cell.ch.is_whitespace() {
|
if !cell.ch.is_whitespace() {
|
||||||
insert_attrs(
|
insert_attrs(
|
||||||
cell,
|
cell,
|
||||||
|
color_model,
|
||||||
&attr_list,
|
&attr_list,
|
||||||
byte_offset as u32,
|
byte_offset as u32,
|
||||||
(byte_offset + len) 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 {
|
if cell.attrs.italic {
|
||||||
let mut attr = pango::Attribute::new_style(pango::Style::Italic).unwrap();
|
let mut attr = pango::Attribute::new_style(pango::Style::Italic).unwrap();
|
||||||
attr.set_start_index(start_idx);
|
attr.set_start_index(start_idx);
|
||||||
|
Loading…
Reference in New Issue
Block a user