Progress...

This commit is contained in:
daa84 2017-08-23 12:45:56 +03:00
parent b6e16cc969
commit aad5dc2112
8 changed files with 137 additions and 107 deletions

19
src/color.rs Normal file
View File

@ -0,0 +1,19 @@
use gdk;
#[derive(Clone, PartialEq)]
pub struct Color(pub f64, pub f64, pub f64);
pub const COLOR_BLACK: Color = Color(0.0, 0.0, 0.0);
pub const COLOR_WHITE: Color = Color(1.0, 1.0, 1.0);
pub const COLOR_RED: Color = Color(1.0, 0.0, 0.0);
impl <'a> Into<gdk::RGBA> for &'a Color {
fn into(self) -> gdk::RGBA {
gdk::RGBA {
red: self.0,
green: self.1,
blue: self.2,
alpha: 1.0,
}
}
}

View File

@ -1,5 +1,5 @@
use cairo;
use ui_model::Color;
use color::Color;
use ui::UiMutex;
use shell;
use mode;

View File

@ -24,6 +24,7 @@ extern crate toml;
mod sys;
mod color;
mod value;
mod mode;
mod ui_model;

View File

@ -2,26 +2,27 @@ use sys::pango::*;
use pango;
use pango::prelude::*;
use cairo;
use pangocairo::CairoContextExt;
use pangocairo::{CairoContextExt, FontMap};
use std::ffi::CString;
pub fn render(ctx: &cairo::Context, font_desc: pango::FontDescription) {
let pango_context = ctx.create_pango_context();
pango_context.set_font_description(&font_desc);
let font_map = FontMap::get_default();
let pango_context = font_map.create_context().unwrap();
pango_context.set_font_description(&font_desc);
let text = "TEST String".to_owned().into_bytes();
let len = text.len();
let text = CString::new(text).unwrap();
let attr_list = pango::AttrList::new();
let text = "TEST String".to_owned().into_bytes();
let len = text.len();
let text = CString::new(text).unwrap();
let attr_list = pango::AttrList::new();
ctx.move_to(0.0, 50.0);
let items = pango_itemize(&pango_context, &text, 0, len, &attr_list);
for item in items {
let mut glyphs = pango::GlyphString::new();
let analysis = item.analysis();
pango_shape(&text, len, &analysis, &mut glyphs);
let font = analysis.font();
let (ink, logical) = glyphs.extents(&font);
ctx.show_glyph_string(&font, &glyphs);
}
ctx.move_to(0.0, 50.0);
let items = pango_itemize(&pango_context, &text, 0, len, &attr_list);
for item in items {
let mut glyphs = pango::GlyphString::new();
let analysis = item.analysis();
pango_shape(&text, len, &analysis, &mut glyphs);
let font = analysis.font();
let (ink, logical) = glyphs.extents(&font);
ctx.show_glyph_string(&font, &glyphs);
}
}

View File

@ -19,7 +19,8 @@ use neovim_lib::{Neovim, NeovimApi, Value};
use neovim_lib::neovim_api::Tabpage;
use settings::{Settings, FontSource};
use ui_model::{UiModel, Cell, Attrs, Color, ModelRect, COLOR_BLACK, COLOR_WHITE, COLOR_RED};
use ui_model::{UiModel, Cell, Attrs, ModelRect};
use color::{Color, COLOR_BLACK, COLOR_WHITE, COLOR_RED};
use nvim;
use nvim::{RedrawEvents, GuiApi, RepaintMode, ErrorReport, NeovimClient};
use input;

63
src/ui_model/cell.rs Normal file
View File

@ -0,0 +1,63 @@
use color::Color;
#[derive(Clone)]
pub struct Attrs {
pub italic: bool,
pub bold: bool,
pub underline: bool,
pub undercurl: bool,
pub foreground: Option<Color>,
pub background: Option<Color>,
pub special: Option<Color>,
pub reverse: bool,
pub double_width: bool,
}
impl Attrs {
pub fn new() -> Attrs {
Attrs {
foreground: None,
background: None,
special: None,
italic: false,
bold: false,
underline: false,
undercurl: false,
reverse: false,
double_width: false,
}
}
fn clear(&mut self) {
self.italic = false;
self.bold = false;
self.underline = false;
self.undercurl = false;
self.reverse = false;
self.foreground = None;
self.background = None;
self.special = None;
self.double_width = false;
}
}
#[derive(Clone)]
pub struct Cell {
pub ch: char,
pub attrs: Attrs,
}
impl Cell {
pub fn new(ch: char) -> Cell {
Cell {
ch: ch,
attrs: Attrs::new(),
}
}
pub fn clear(&mut self) {
self.ch = ' ';
self.attrs.clear();
}
}

23
src/ui_model/line.rs Normal file
View File

@ -0,0 +1,23 @@
use super::cell::Cell;
use pango::Item;
pub struct Line {
line: Box<[Cell]>,
item_line: Option<Box<[Item]>>,
cell_to_item: Box<[usize]>,
}
impl Line {
pub fn new(columns: usize) -> Self {
let line = Vec::with_capacity(columns);
for _ in 0..columns {
line.push(Cell::new(' '));
}
Line {
cell_to_item: Vec::with_capacity(line.len()).into_boxed_slice(),
line: line.into_boxed_slice(),
item_line: None,
}
}
}

View File

@ -1,92 +1,17 @@
mod cell;
mod line;
pub use self::cell::{Cell, Attrs};
use self::line::Line;
use std::slice::Iter;
use gdk;
#[derive(Clone, PartialEq)]
pub struct Color(pub f64, pub f64, pub f64);
pub const COLOR_BLACK: Color = Color(0.0, 0.0, 0.0);
pub const COLOR_WHITE: Color = Color(1.0, 1.0, 1.0);
pub const COLOR_RED: Color = Color(1.0, 0.0, 0.0);
impl <'a> Into<gdk::RGBA> for &'a Color {
fn into(self) -> gdk::RGBA {
gdk::RGBA {
red: self.0,
green: self.1,
blue: self.2,
alpha: 1.0,
}
}
}
#[derive(Clone)]
pub struct Attrs {
pub italic: bool,
pub bold: bool,
pub underline: bool,
pub undercurl: bool,
pub foreground: Option<Color>,
pub background: Option<Color>,
pub special: Option<Color>,
pub reverse: bool,
pub double_width: bool,
}
impl Attrs {
pub fn new() -> Attrs {
Attrs {
foreground: None,
background: None,
special: None,
italic: false,
bold: false,
underline: false,
undercurl: false,
reverse: false,
double_width: false,
}
}
fn clear(&mut self) {
self.italic = false;
self.bold = false;
self.underline = false;
self.undercurl = false;
self.reverse = false;
self.foreground = None;
self.background = None;
self.special = None;
self.double_width = false;
}
}
#[derive(Clone)]
pub struct Cell {
pub ch: char,
pub attrs: Attrs,
}
impl Cell {
pub fn new(ch: char) -> Cell {
Cell {
ch: ch,
attrs: Attrs::new(),
}
}
fn clear(&mut self) {
self.ch = ' ';
self.attrs.clear();
}
}
pub struct UiModel {
pub columns: usize,
pub rows: usize,
cur_row: usize,
cur_col: usize,
model: Vec<Vec<Cell>>,
model: Box<[Line]>,
top: usize,
bot: usize,
left: usize,
@ -97,10 +22,7 @@ impl UiModel {
pub fn new(rows: u64, columns: u64) -> UiModel {
let mut model = Vec::with_capacity(rows as usize);
for i in 0..rows as usize {
model.push(Vec::with_capacity(columns as usize));
for _ in 0..columns as usize {
model[i].push(Cell::new(' '));
}
model.push(Line::new(columns as usize));
}
UiModel {
@ -108,7 +30,7 @@ impl UiModel {
rows: rows as usize,
cur_row: 0,
cur_col: 0,
model: model,
model: model.into_boxed_slice(),
top: 0,
bot: (rows - 1) as usize,
left: 0,
@ -116,7 +38,7 @@ impl UiModel {
}
}
pub fn model(&self) -> &Vec<Vec<Cell>> {
pub fn model(&self) -> &[Line] {
&self.model
}