add bold/italic settings

This commit is contained in:
daa84 2016-04-01 12:34:55 +03:00
parent 8a763c928e
commit a2813a84c7
2 changed files with 28 additions and 8 deletions

View File

@ -115,10 +115,7 @@ fn gtk_draw(drawing_area: &DrawingArea, ctx: &cairo::Context) -> Inhibit {
ctx.paint();
ctx.set_source_rgb(1.0, 1.0, 1.0);
let font_face = cairo::FontFace::toy_create("",
cairo::enums::FontSlant::Normal,
cairo::enums::FontWeight::Normal);
ctx.set_font_face(font_face);
let font_extents = ctx.font_extents();
UI.with(|ui_cell| {
@ -128,12 +125,30 @@ fn gtk_draw(drawing_area: &DrawingArea, ctx: &cairo::Context) -> Inhibit {
for line in ui.model.model() {
ctx.move_to(0.0, line_y - font_extents.descent);
for cell in line {
let slant = if cell.attrs.italic {
cairo::enums::FontSlant::Italic
} else {
cairo::enums::FontSlant::Normal
};
let weight = if cell.attrs.bold {
cairo::enums::FontWeight::Bold
} else {
cairo::enums::FontWeight::Normal
};
let font_face = cairo::FontFace::toy_create("", slant, weight);
ctx.set_font_face(font_face);
let bg = &cell.attrs.background;
ctx.set_source_rgb(bg.0, bg.1, bg.2);
//ctx.set_source_rgb(1.0, 0.0 , 0.0);
// ctx.set_source_rgb(1.0, 0.0 , 0.0);
let text_extents = ctx.text_extents(&cell.ch.to_string());
let current_point = ctx.get_current_point();
ctx.rectangle(current_point.0, line_y - font_extents.height, text_extents.width, font_extents.height);
ctx.rectangle(current_point.0,
line_y - font_extents.height,
text_extents.width,
font_extents.height);
ctx.fill();
ctx.move_to(current_point.0, current_point.1);
@ -169,7 +184,6 @@ impl RedrawEvents for Ui {
self.drawing_area.queue_draw();
}
// highlight_set([Map([(String("bold"), Boolean(true)), (String("foreground"), Integer(U64(255)))])])
fn on_highlight_set(&mut self, attrs: &HashMap<String, Value>) {
let mut model_attrs = Attrs::new();
if let Some(&Value::Integer(Integer::U64(fg))) = attrs.get("foreground") {
@ -181,6 +195,8 @@ impl RedrawEvents for Ui {
if attrs.contains_key("reverse") {
mem::swap(&mut model_attrs.foreground, &mut model_attrs.background);
}
model_attrs.bold = attrs.contains_key("bold");
model_attrs.italic = attrs.contains_key("italic");
self.cur_attrs = Some(model_attrs);
}
}

View File

@ -7,6 +7,8 @@ const COLOR_WHITE: Color = Color(1.0, 1.0, 1.0);
#[derive(Clone)]
pub struct Attrs {
pub italic: bool,
pub bold: bool,
pub foreground: Color,
pub background: Color,
}
@ -16,6 +18,8 @@ impl Attrs {
Attrs {
foreground: COLOR_WHITE,
background: COLOR_BLACK,
italic: false,
bold: false,
}
}
}