From 642fd772f04120993939bf71c4ce680d155c37c4 Mon Sep 17 00:00:00 2001 From: daa Date: Sun, 14 Jan 2018 22:18:40 +0300 Subject: [PATCH] Test, fix model layout calculation, fix build --- appveyor.yml | 2 +- src/sys/pango/item.rs | 5 ----- src/ui_model/mod.rs | 2 +- src/ui_model/model_layout.rs | 38 +++++++++++++++++++++++++----------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 36154b2..99dd72a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ environment: PROJECT_NAME: rustfmt matrix: - TARGET: x86_64-pc-windows-gnu - RUST_VERSION: 1.20.0 + RUST_VERSION: 1.23.0 install: # - ps: Start-FileDownload "https://static.rust-lang.org/dist/channel-rust-stable" diff --git a/src/sys/pango/item.rs b/src/sys/pango/item.rs index 0237edb..036ecbf 100644 --- a/src/sys/pango/item.rs +++ b/src/sys/pango/item.rs @@ -20,11 +20,6 @@ glib_wrapper! { } impl Item { - #[cfg(test)] - pub fn new() -> Self { - unsafe { from_glib_full(pango_sys::pango_item_new()) } - } - pub fn analysis(&self) -> analysis::Analysis { analysis::Analysis::from(&self.0.analysis) } diff --git a/src/ui_model/mod.rs b/src/ui_model/mod.rs index 5bb14e5..1ac54f9 100644 --- a/src/ui_model/mod.rs +++ b/src/ui_model/mod.rs @@ -127,7 +127,7 @@ impl UiModel { pub fn copy_rows(&self, target: &mut UiModel, to_row: usize) { for (row_idx, line) in self.model[0..to_row + 1].iter().enumerate() { let mut target_row = &mut target.model[row_idx]; - line.copy_to(target_row, 0, self.columns); + line.copy_to(target_row, 0, self.columns - 1); } } diff --git a/src/ui_model/model_layout.rs b/src/ui_model/model_layout.rs index 5494865..7a482e6 100644 --- a/src/ui_model/model_layout.rs +++ b/src/ui_model/model_layout.rs @@ -29,10 +29,11 @@ impl ModelLayout { fn check_model_size(&mut self, rows: usize) { if rows > self.model.rows { let model_cols = self.model.columns; - let model_rows = ((rows / ModelLayout::ROWS_STEP) + 1) * ModelLayout::ROWS_STEP; + let model_rows = ((rows / (ModelLayout::ROWS_STEP + 1)) + 1) * ModelLayout::ROWS_STEP; let mut model = UiModel::new(model_rows as u64, model_cols as u64); - self.model.copy_rows(&mut model, self.rows_filled); + self.model.copy_rows(&mut model, self.rows_filled - 1); + self.model = model; } } @@ -55,25 +56,25 @@ impl ModelLayout { for content in lines { for &(ref attr, ref ch_list) in content { for ch in ch_list { - if col_idx >= self.model.columns { - col_idx = 0; - row_idx += 1; - } else { - col_idx += 1; - } + self.model.set_cursor(row_idx, col_idx as usize); + self.model.put(*ch, false, attr.as_ref()); if max_col_idx < col_idx { max_col_idx = col_idx; } - self.model.set_cursor(row_idx, col_idx as usize); - self.model.put(*ch, false, attr.as_ref()); + col_idx += 1; + + if col_idx >= self.model.columns { + col_idx = 0; + row_idx += 1; + } } } row_idx += 1; } - (max_col_idx + 1, rows) + (max_col_idx + 1, self.rows_filled) } fn count_lines(lines: &Vec, Vec)>>, max_columns: usize) -> usize { @@ -99,4 +100,19 @@ mod tests { let rows = ModelLayout::count_lines(&lines, 4); assert_eq!(2, rows); } + + #[test] + fn test_resize() { + let lines = vec![vec![(None, vec!['a'; 5])]; ModelLayout::ROWS_STEP]; + let mut model = ModelLayout::new(5); + + let (cols, rows) = model.layout(&lines); + assert_eq!(5, cols); + assert_eq!(ModelLayout::ROWS_STEP, rows); + + let (cols, rows) = model.layout_append(&lines); + assert_eq!(5, cols); + assert_eq!(ModelLayout::ROWS_STEP * 2, rows); + assert_eq!(ModelLayout::ROWS_STEP * 2, model.model.rows); + } }