Starting point on fix of grapheme rendering

This commit is contained in:
daa
2018-04-08 00:04:31 +03:00
parent d8d33edb19
commit 2b818d0847
8 changed files with 31 additions and 19 deletions

View File

@@ -28,7 +28,7 @@ pub struct Level {
}
impl Level {
pub fn insert(&mut self, c: &str, shift: bool, render_state: &shell::RenderState) {
pub fn insert(&mut self, c: String, shift: bool, render_state: &shell::RenderState) {
self.model_layout.insert_char(c, shift);
self.update_preferred_size(render_state);
}
@@ -405,7 +405,7 @@ impl CmdLine {
let mut state = self.state.borrow_mut();
if let Some(level) = state.levels.get_mut((level - 1) as usize) {
level.insert(&c, shift, render_state);
level.insert(c, shift, render_state);
level.update_cache(&*render_state);
} else {
error!("Level {} does not exists", level);

View File

@@ -1156,9 +1156,8 @@ impl State {
}
pub fn on_put(&mut self, text: String) -> RepaintMode {
let ch = text.chars().last().unwrap_or(' ');
let double_width = text.is_empty();
RepaintMode::Area(self.model.put(ch, double_width, self.cur_attrs.as_ref()))
RepaintMode::Area(self.model.put(text, double_width, self.cur_attrs.as_ref()))
}
pub fn on_clear(&mut self) -> RepaintMode {

View File

@@ -76,24 +76,30 @@ impl Attrs {
}
}
const EMPTY_STRING: String = String::new();
#[derive(Clone)]
pub struct Cell {
pub attrs: Attrs,
pub ch: char,
pub ch: String,
pub dirty: bool,
}
impl Cell {
pub fn new(ch: char) -> Cell {
pub fn new_empty() -> Cell {
Cell::new(EMPTY_STRING)
}
pub fn new(ch: String) -> Cell {
Cell {
attrs: Attrs::new(),
ch: ch,
ch,
dirty: true,
}
}
pub fn clear(&mut self) {
self.ch = ' ';
self.ch = EMPTY_STRING;
self.attrs.clear();
self.dirty = true;
}

View File

@@ -21,7 +21,7 @@ pub struct Line {
impl Line {
pub fn new(columns: usize) -> Self {
Line {
line: vec![Cell::new(' '); columns].into_boxed_slice(),
line: vec![Cell::new_empty(); columns].into_boxed_slice(),
item_line: vec![None; columns].into_boxed_slice(),
cell_to_item: vec![-1; columns].into_boxed_slice(),
dirty_line: true,
@@ -257,7 +257,7 @@ impl StyledLine {
continue;
}
line_str.push(cell.ch);
line_str.push_str(&cell.ch);
let len = line_str.len() - byte_offset;
for _ in 0..len {

View File

@@ -93,7 +93,7 @@ impl UiModel {
(self.cur_row, self.cur_col)
}
pub fn put(&mut self, ch: char, double_width: bool, attrs: Option<&Attrs>) -> ModelRect {
pub fn put(&mut self, ch: String, double_width: bool, attrs: Option<&Attrs>) -> ModelRect {
let mut changed_region = self.cur_point();
let line = &mut self.model[self.cur_row];
line.dirty_line = true;

View File

@@ -8,7 +8,7 @@ pub struct ModelLayout {
pub model: UiModel,
rows_filled: usize,
cols_filled: usize,
lines: Vec<Vec<(Option<Attrs>, Vec<char>)>>,
lines: Vec<Vec<(Option<Attrs>, Vec<String>)>>,
}
impl ModelLayout {
@@ -23,7 +23,7 @@ impl ModelLayout {
}
}
pub fn layout_append(&mut self, mut lines: Vec<Vec<(Option<Attrs>, Vec<char>)>>) {
pub fn layout_append(&mut self, mut lines: Vec<Vec<(Option<Attrs>, Vec<String>)>>) {
let rows_filled = self.rows_filled;
let take_from = self.lines.len();
@@ -32,7 +32,7 @@ impl ModelLayout {
self.layout_replace(rows_filled, take_from);
}
pub fn layout(&mut self, lines: Vec<Vec<(Option<Attrs>, Vec<char>)>>) {
pub fn layout(&mut self, lines: Vec<Vec<(Option<Attrs>, Vec<String>)>>) {
self.lines = lines;
self.layout_replace(0, 0);
}
@@ -67,12 +67,11 @@ impl ModelLayout {
}
}
pub fn insert_char(&mut self, c: &str, shift: bool) {
if c.is_empty() {
pub fn insert_char(&mut self, ch: String, shift: bool) {
if ch.is_empty() {
return;
}
let ch = c.chars().next().unwrap();
let (row, col) = self.model.get_cursor();
if shift {
@@ -85,7 +84,7 @@ impl ModelLayout {
self.model.set_cursor(row, col);
}
fn insert_into_lines(&mut self, ch: char) {
fn insert_into_lines(&mut self, ch: String) {
let line = &mut self.lines[0];
let cur_col = self.model.cur_col;
@@ -152,7 +151,7 @@ impl ModelLayout {
}
}
fn count_lines(lines: &[Vec<(Option<Attrs>, Vec<char>)>], max_columns: usize) -> usize {
fn count_lines(lines: &[Vec<(Option<Attrs>, Vec<String>)>], max_columns: usize) -> usize {
let mut row_count = 0;
for line in lines {