Number of fixes

This commit is contained in:
daa 2017-04-22 22:18:59 +03:00
parent 552021d2be
commit 0f919ec390
3 changed files with 64 additions and 12 deletions

View File

@ -258,7 +258,7 @@ impl<T> ErrorReport for result::Result<T, CallError> {
} }
} }
#[derive(Clone)] #[derive(Clone, Debug)]
pub enum RepaintMode { pub enum RepaintMode {
Nothing, Nothing,
All, All,
@ -267,6 +267,7 @@ pub enum RepaintMode {
} }
impl RepaintMode { impl RepaintMode {
// [TODO]: Remove clones - 2017-04-22 09:46
pub fn join(&self, mode: &RepaintMode) -> RepaintMode { pub fn join(&self, mode: &RepaintMode) -> RepaintMode {
match (self, mode) { match (self, mode) {
(&RepaintMode::Nothing, m) => m.clone(), (&RepaintMode::Nothing, m) => m.clone(),
@ -278,8 +279,12 @@ impl RepaintMode {
vec.join(mr2); vec.join(mr2);
RepaintMode::AreaList(vec) RepaintMode::AreaList(vec)
} }
(&RepaintMode::AreaList(_), &RepaintMode::AreaList(_)) => { (&RepaintMode::AreaList(ref target), &RepaintMode::AreaList(ref source)) => {
panic!("Not implmeneted"); let mut list = target.clone();
for s in &source.list {
list.join(&s);
}
RepaintMode::AreaList(list)
} }
(&RepaintMode::AreaList(ref l1), &RepaintMode::Area(ref l2)) => { (&RepaintMode::AreaList(ref l1), &RepaintMode::Area(ref l2)) => {
let mut list = l1.clone(); let mut list = l1.clone();

View File

@ -702,7 +702,7 @@ fn gtk_configure_event(state: &Arc<UiMutex<State>>, ev: &EventConfigure) -> bool
impl RedrawEvents for State { impl RedrawEvents for State {
fn on_cursor_goto(&mut self, row: u64, col: u64) -> RepaintMode { fn on_cursor_goto(&mut self, row: u64, col: u64) -> RepaintMode {
RepaintMode::Area(self.model.set_cursor(row as usize, col as usize)) RepaintMode::AreaList(self.model.set_cursor(row as usize, col as usize))
} }
fn on_put(&mut self, text: &str) -> RepaintMode { fn on_put(&mut self, text: &str) -> RepaintMode {

View File

@ -138,8 +138,8 @@ impl UiModel {
ModelRect::point(self.cur_col, self.cur_row) ModelRect::point(self.cur_col, self.cur_row)
} }
pub fn set_cursor(&mut self, row: usize, col: usize) -> ModelRect { pub fn set_cursor(&mut self, row: usize, col: usize) -> ModelRectVec {
let mut changed_region = self.cur_point(); let mut changed_region = ModelRectVec::new(self.cur_point());
self.cur_row = row; self.cur_row = row;
self.cur_col = col; self.cur_col = col;
@ -230,7 +230,7 @@ impl UiModel {
} }
} }
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct ModelRectVec { pub struct ModelRectVec {
pub list: Vec<ModelRect>, pub list: Vec<ModelRect>,
} }
@ -249,7 +249,9 @@ impl ModelRectVec {
rect.right == neighbor.right + 1) && rect.right == neighbor.right + 1) &&
neighbor.in_vertical(rect) { neighbor.in_vertical(rect) {
return Some(i); return Some(i);
} else if rect == neighbor { } else if rect.in_horizontal(neighbor) && rect.in_vertical(neighbor) {
return Some(i);
} else if rect.contains(neighbor) {
return Some(i); return Some(i);
} }
} }
@ -307,6 +309,13 @@ impl ModelRect {
other.bot >= self.top && other.bot <= self.bot other.bot >= self.top && other.bot <= self.bot
} }
fn contains(&self, other: &ModelRect) -> bool {
self.top <= other.top &&
self.bot >= other.bot &&
self.left <= other.left &&
self.right >= other.right
}
pub fn extend(&mut self, top: usize, bot: usize, left: usize, right: usize) { pub fn extend(&mut self, top: usize, bot: usize, left: usize, right: usize) {
if self.top > 0 { if self.top > 0 {
self.top -= top; self.top -= top;
@ -466,6 +475,16 @@ impl<'a> Iterator for ClipColIterator<'a> {
mod tests { mod tests {
use super::*; use super::*;
#[test]
fn test_vec_join_inside() {
let mut list = ModelRectVec::new(ModelRect::new(0, 23, 0, 69));
let inside = ModelRect::new(23, 23, 68, 69);
list.join(&inside);
assert_eq!(1, list.list.len());
}
#[test] #[test]
fn test_vec_join_top() { fn test_vec_join_top() {
let mut list = ModelRectVec::new(ModelRect::point(0, 0)); let mut list = ModelRectVec::new(ModelRect::point(0, 0));
@ -476,6 +495,26 @@ mod tests {
assert_eq!(1, list.list.len()); assert_eq!(1, list.list.len());
} }
#[test]
fn test_model_vec_join_right() {
let mut list = ModelRectVec::new(ModelRect::new(23, 23, 69, 69));
let neighbor = ModelRect::new(23, 23, 69, 70);
list.join(&neighbor);
assert_eq!(1, list.list.len());
}
#[test]
fn test_model_vec_join_right2() {
let mut list = ModelRectVec::new(ModelRect::new(0, 1, 0, 9));
let neighbor = ModelRect::new(1, 1, 9, 10);
list.join(&neighbor);
assert_eq!(1, list.list.len());
}
#[test] #[test]
fn test_model_vec_join() { fn test_model_vec_join() {
let mut list = ModelRectVec::new(ModelRect::point(5, 5)); let mut list = ModelRectVec::new(ModelRect::point(5, 5));
@ -558,10 +597,18 @@ mod tests {
let rect = model.set_cursor(5, 5); let rect = model.set_cursor(5, 5);
assert_eq!(1, rect.top); assert_eq!(2, rect.list.len());
assert_eq!(1, rect.left);
assert_eq!(5, rect.bot); assert_eq!(1, rect.list[0].top);
assert_eq!(5, rect.right); assert_eq!(1, rect.list[0].left);
assert_eq!(1, rect.list[0].bot);
assert_eq!(1, rect.list[0].right);
assert_eq!(5, rect.list[1].top);
assert_eq!(5, rect.list[1].left);
assert_eq!(5, rect.list[1].bot);
assert_eq!(5, rect.list[1].right);
} }
#[test] #[test]