Support for double width chars
This commit is contained in:
parent
df3b54b8a4
commit
b4deb823aa
16
src/ui.rs
16
src/ui.rs
@ -382,7 +382,7 @@ fn draw(ui: &Ui, ctx: &cairo::Context) {
|
||||
ctx.move_to(0.0, line_y);
|
||||
|
||||
for (col_idx, cell) in line.iter().enumerate() {
|
||||
|
||||
let double_width = line.get(col_idx + 1).map(|c| c.attrs.double_width).unwrap_or(false);
|
||||
let current_point = ctx.get_current_point();
|
||||
|
||||
let (bg, fg) = ui.colors(cell);
|
||||
@ -393,7 +393,11 @@ fn draw(ui: &Ui, ctx: &cairo::Context) {
|
||||
let cursor_width = if ui.mode == NvimMode::Insert {
|
||||
char_width / 5.0
|
||||
} else {
|
||||
char_width
|
||||
if double_width {
|
||||
char_width * 2.0
|
||||
} else {
|
||||
char_width
|
||||
}
|
||||
};
|
||||
|
||||
ctx.rectangle(current_point.0, line_y, cursor_width, line_height);
|
||||
@ -410,6 +414,14 @@ fn draw(ui: &Ui, ctx: &cairo::Context) {
|
||||
buf.push(cell.ch);
|
||||
layout.set_text(&buf, -1);
|
||||
|
||||
// correct layout for double_width chars
|
||||
if double_width {
|
||||
let (dw_width, dw_height) = layout.get_pixel_size();
|
||||
let x_offset = (char_width * 2.0 - dw_width as f64) / 2.0;
|
||||
let y_offset = (line_height - dw_height as f64) / 2.0;
|
||||
ctx.rel_move_to(x_offset, y_offset);
|
||||
}
|
||||
|
||||
ctx.set_source_rgb(fg.0, fg.1, fg.2);
|
||||
pc::update_layout(ctx, &layout);
|
||||
pc::show_layout(ctx, &layout);
|
||||
|
@ -16,6 +16,7 @@ pub struct Attrs {
|
||||
pub background: Option<Color>,
|
||||
pub special: Option<Color>,
|
||||
pub reverse: bool,
|
||||
pub double_width: bool,
|
||||
}
|
||||
|
||||
impl Attrs {
|
||||
@ -29,6 +30,7 @@ impl Attrs {
|
||||
underline: false,
|
||||
undercurl: false,
|
||||
reverse: false,
|
||||
double_width: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +43,7 @@ impl Attrs {
|
||||
self.foreground = None;
|
||||
self.background = None;
|
||||
self.special = None;
|
||||
self.double_width = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,8 +131,9 @@ impl UiModel {
|
||||
|
||||
pub fn put(&mut self, text: &str, attrs: Option<&Attrs>) {
|
||||
let mut cell = &mut self.model[self.cur_row][self.cur_col];
|
||||
cell.ch = text.chars().last().unwrap();
|
||||
cell.ch = text.chars().last().unwrap_or(' ');
|
||||
cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(|| Attrs::new());
|
||||
cell.attrs.double_width = text.len() == 0;
|
||||
self.cur_col += 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user