From 506c41c0f86756ea930077d1837e5c047aa5f816 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 14 May 2015 17:48:24 -0700 Subject: [PATCH] Fix some warnings --- src/div.rs | 3 +-- src/stack_view.rs | 8 ++++++++ src/text_view.rs | 32 ++++++++++++++------------------ 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/div.rs b/src/div.rs index 4f69031..b8fc1d2 100644 --- a/src/div.rs +++ b/src/div.rs @@ -1,6 +1,5 @@ pub fn div_up_usize(p: usize, q: usize) -> usize { - if p % q == 0 { p/q } - else { 1 + p/q } + div_up(p as u32, q as u32) as usize } pub fn div_up(p: u32, q: u32) -> u32 { diff --git a/src/stack_view.rs b/src/stack_view.rs index cd83576..b0eaebb 100644 --- a/src/stack_view.rs +++ b/src/stack_view.rs @@ -16,10 +16,18 @@ impl StackView { layers: Vec::new(), } } + + pub fn add_layer(&mut self, view: Box) { + self.layers.push(view); + } } impl View for StackView { fn draw(&self, win: ncurses::WINDOW, size: Size) { + match self.layers.last() { + None => (), + Some(v) => v.draw(win, size), + } } } diff --git a/src/text_view.rs b/src/text_view.rs index 623e2ae..7948238 100644 --- a/src/text_view.rs +++ b/src/text_view.rs @@ -1,5 +1,3 @@ -use std::cmp::max; - use ncurses; use super::Size; @@ -13,18 +11,16 @@ pub struct TextView { /// Returns the number of lines required to display the given text with the /// specified maximum line width. -fn get_line_span(line: &str, maxWidth: usize) -> usize { +fn get_line_span(line: &str, max_width: usize) -> usize { let mut lines = 1; let mut length = 0; - line.split(" ") - .map(|word| word.len()) - .map(|l| { - length += l; - if length > maxWidth { - length = l; - lines += 1; - } - }); + for l in line.split(" ").map(|word| word.len()) { + length += l; + if length > max_width { + length = l; + lines += 1; + } + } lines } @@ -38,15 +34,15 @@ impl TextView { /// Returns the number of lines required to display the content /// with the given width. - fn get_num_lines(&self, maxWidth: usize) -> usize { + fn get_num_lines(&self, max_width: usize) -> usize { self.content.split("\n") - .map(|line| get_line_span(line, maxWidth)) + .map(|line| get_line_span(line, max_width)) .fold(0, |sum, x| sum + x) } - fn get_num_cols(&self, maxHeight: usize) -> usize { - (div_up_usize(self.content.len(), maxHeight)..self.content.len()) - .find(|w| self.get_num_lines(*w) <= maxHeight) + fn get_num_cols(&self, max_height: usize) -> usize { + (div_up_usize(self.content.len(), max_height)..self.content.len()) + .find(|w| self.get_num_lines(*w) <= max_height) .unwrap() } } @@ -66,7 +62,7 @@ impl View for TextView { let w = self.get_num_cols(h as usize) as u32; Size::new(w, h) }, - (DimensionRequest::AtMost(w),DimensionRequest::AtMost(h)) => unreachable!(), + (DimensionRequest::AtMost(_),DimensionRequest::AtMost(_)) => unreachable!(), _ => unreachable!(), } }