neovim-gtk/src/ui_model.rs

64 lines
1.3 KiB
Rust
Raw Normal View History

2016-03-19 08:47:23 +00:00
pub struct Cell {
ch: char,
}
impl Cell {
pub fn new(ch: char) -> Cell {
Cell { ch: ch }
}
2016-03-29 09:22:16 +00:00
fn clear(&mut self) {
self.ch = ' ';
}
2016-03-19 08:47:23 +00:00
}
pub struct UiModel {
2016-03-28 15:05:10 +00:00
columns: usize,
rows: usize,
cur_row: usize,
cur_col: usize,
model: Vec<Vec<Cell>>,
2016-03-19 08:47:23 +00:00
}
impl UiModel {
2016-03-19 10:27:39 +00:00
pub fn empty() -> UiModel {
UiModel::new(0, 0)
}
2016-03-28 15:05:10 +00:00
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(' '));
}
2016-03-19 08:47:23 +00:00
}
UiModel {
2016-03-28 15:05:10 +00:00
columns: columns as usize,
rows: rows as usize,
2016-03-19 08:47:23 +00:00
cur_row: 0,
cur_col: 0,
model: model,
}
}
2016-03-28 14:03:21 +00:00
pub fn set_cursor(&mut self, row: u64, col: u64) {
2016-03-28 15:05:10 +00:00
self.cur_col = col as usize;
self.cur_row = row as usize;
}
pub fn put(&mut self, text: &str) {
self.model[self.cur_row][self.cur_col].ch = text.chars().last().unwrap();
self.cur_col += 1;
2016-03-19 08:47:23 +00:00
}
2016-03-29 09:22:16 +00:00
pub fn clear(&mut self) {
for row in 0..self.rows {
for col in 0..self.columns {
self.model[row][col].clear();
}
}
}
2016-03-19 08:47:23 +00:00
}