Merge branch 'master' into ext_cmdline

This commit is contained in:
daa
2018-01-01 17:56:10 +03:00
39 changed files with 996 additions and 679 deletions

View File

@@ -57,7 +57,7 @@ struct ContextState {
impl ContextState {
pub fn new(font_desc: pango::FontDescription) -> Self {
let font_map = FontMap::get_default();
let font_map = FontMap::get_default().unwrap();
let pango_context = font_map.create_context().unwrap();
pango_context.set_font_description(&font_desc);

View File

@@ -9,10 +9,12 @@ use self::model_clip_iterator::{RowView, ModelClipIteratorFactory};
use mode;
use color;
use sys::pango::*;
use sys::pangocairo::*;
use pango;
use cairo;
use pangocairo;
use cursor;
use pangocairo::CairoContextExt;
use ui_model;
pub fn render<RC: cursor::CursorRedrawCb + 'static>(
@@ -34,6 +36,15 @@ pub fn render<RC: cursor::CursorRedrawCb + 'static>(
let &CellMetrics { char_width, .. } = cell_metrics;
let (cursor_row, cursor_col) = ui_model.get_cursor();
for cell_view in ui_model.get_clip_iterator(ctx, cell_metrics) {
let mut line_x = 0.0;
for (col, cell) in cell_view.line.line.iter().enumerate() {
draw_cell_bg(&cell_view, color_model, cell, col, line_x);
line_x += char_width;
}
}
for cell_view in ui_model.get_clip_iterator(ctx, cell_metrics) {
let mut line_x = 0.0;
let RowView { line, row, line_y, .. } = cell_view;
@@ -44,7 +55,6 @@ pub fn render<RC: cursor::CursorRedrawCb + 'static>(
draw_underline(&cell_view, color_model, cell, line_x);
if row == cursor_row && col == cursor_col {
let double_width = line.line.get(col + 1).map_or(
false,
@@ -96,7 +106,7 @@ fn draw_underline(
let undercurl_height = (underline_thickness * 4.0).min(max_undercurl_height);
let undercurl_y = line_y + underline_position - undercurl_height / 2.0;
ctx.show_error_underline(line_x, undercurl_y, char_width, undercurl_height);
pangocairo::functions::error_underline_path(ctx, line_x, undercurl_y, char_width, undercurl_height);
} else if cell.attrs.underline {
let fg = color_model.actual_cell_fg(cell);
ctx.set_source_rgb(fg.0, fg.1, fg.2);
@@ -108,6 +118,48 @@ fn draw_underline(
}
}
fn draw_cell_bg(
cell_view: &RowView,
color_model: &color::ColorModel,
cell: &ui_model::Cell,
col: usize,
line_x: f64,
) {
let &RowView {
ctx,
line,
line_y,
cell_metrics: &CellMetrics {
char_width,
line_height,
..
},
..
} = cell_view;
let bg = color_model.cell_bg(cell);
if let Some(bg) = bg {
if !line.is_binded_to_item(col) {
if bg != &color_model.bg_color {
ctx.set_source_rgb(bg.0, bg.1, bg.2);
ctx.rectangle(line_x, line_y, char_width, line_height);
ctx.fill();
}
} else {
ctx.set_source_rgb(bg.0, bg.1, bg.2);
ctx.rectangle(
line_x,
line_y,
char_width * line.item_len_from_idx(col) as f64,
line_height,
);
ctx.fill();
}
}
}
fn draw_cell(
cell_view: &RowView,
color_model: &color::ColorModel,
@@ -121,41 +173,22 @@ fn draw_cell(
line,
line_y,
cell_metrics: &CellMetrics {
char_width,
line_height,
ascent,
..
},
..
} = cell_view;
let (bg, fg) = color_model.cell_colors(cell);
if let Some(item) = line.item_line[col].as_ref() {
if let Some(bg) = bg {
ctx.set_source_rgb(bg.0, bg.1, bg.2);
ctx.rectangle(
line_x,
line_y,
char_width * line.item_len_from_idx(col) as f64,
line_height,
);
ctx.fill();
}
if let Some(ref glyphs) = item.glyphs {
let fg = color_model.actual_cell_fg(cell);
ctx.move_to(line_x, line_y + ascent);
ctx.set_source_rgb(fg.0, fg.1, fg.2);
ctx.show_glyph_string(item.font(), glyphs);
show_glyph_string(ctx, item.font(), glyphs);
}
} else if !line.is_binded_to_item(col) {
let bg = color_model.cell_bg(cell);
if let Some(bg) = bg {
ctx.set_source_rgb(bg.0, bg.1, bg.2);
ctx.rectangle(line_x, line_y, char_width, line_height);
ctx.fill();
}
}
}