Support double_width chars
This commit is contained in:
@@ -4,25 +4,57 @@ use cairo;
|
||||
use super::context::CellMetrics;
|
||||
use ui_model;
|
||||
|
||||
pub struct RowView<'a> {
|
||||
pub row: usize,
|
||||
pub line: &'a ui_model::Line,
|
||||
pub cell_metrics: &'a CellMetrics,
|
||||
pub line_y: f64,
|
||||
pub ctx: &'a cairo::Context,
|
||||
}
|
||||
|
||||
impl<'a> RowView<'a> {
|
||||
pub fn new(
|
||||
row: usize,
|
||||
ctx: &'a cairo::Context,
|
||||
cell_metrics: &'a CellMetrics,
|
||||
line: &'a ui_model::Line,
|
||||
) -> Self {
|
||||
RowView {
|
||||
line,
|
||||
line_y: row as f64 * cell_metrics.line_height,
|
||||
row,
|
||||
cell_metrics,
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ModelClipIterator<'a> {
|
||||
model_idx: usize,
|
||||
model_iter: Iter<'a, ui_model::Line>,
|
||||
cell_metrics: &'a CellMetrics,
|
||||
ctx: &'a cairo::Context,
|
||||
}
|
||||
|
||||
pub trait ModelClipIteratorFactory {
|
||||
fn get_clip_iterator(
|
||||
&self,
|
||||
ctx: &cairo::Context,
|
||||
cell_metrics: &CellMetrics,
|
||||
fn get_clip_iterator<'a>(
|
||||
&'a self,
|
||||
ctx: &'a cairo::Context,
|
||||
cell_metrics: &'a CellMetrics,
|
||||
) -> ModelClipIterator;
|
||||
}
|
||||
|
||||
impl<'a> Iterator for ModelClipIterator<'a> {
|
||||
type Item = (usize, &'a ui_model::Line);
|
||||
type Item = RowView<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<(usize, &'a ui_model::Line)> {
|
||||
fn next(&mut self) -> Option<RowView<'a>> {
|
||||
let next = if let Some(line) = self.model_iter.next() {
|
||||
Some((self.model_idx, line))
|
||||
Some(RowView::new(
|
||||
self.model_idx,
|
||||
self.ctx,
|
||||
self.cell_metrics,
|
||||
line,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -36,11 +68,11 @@ impl<'a> Iterator for ModelClipIterator<'a> {
|
||||
/// this is because in some cases(like 'g' character) drawing character does not fit to calculated bounds
|
||||
/// and if one line must be repainted - also previous and next line must be repainted to
|
||||
impl ModelClipIteratorFactory for ui_model::UiModel {
|
||||
fn get_clip_iterator(
|
||||
&self,
|
||||
ctx: &cairo::Context,
|
||||
cell_metrics: &CellMetrics,
|
||||
) -> ModelClipIterator {
|
||||
fn get_clip_iterator<'a>(
|
||||
&'a self,
|
||||
ctx: &'a cairo::Context,
|
||||
cell_metrics: &'a CellMetrics,
|
||||
) -> ModelClipIterator<'a> {
|
||||
let model = self.model();
|
||||
|
||||
let (x1, y1, x2, y2) = ctx.clip_extents();
|
||||
@@ -59,6 +91,8 @@ impl ModelClipIteratorFactory for ui_model::UiModel {
|
||||
ModelClipIterator {
|
||||
model_idx: model_clip_top,
|
||||
model_iter: model[model_clip_top..model_clip_bot + 1].iter(),
|
||||
ctx,
|
||||
cell_metrics,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user